]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
maint: add a syntax check to avoid unstyled quoting
authorPádraig Brady <P@draigBrady.com>
Wed, 4 Nov 2015 02:44:41 +0000 (02:44 +0000)
committerPádraig Brady <P@draigBrady.com>
Wed, 4 Nov 2015 23:30:15 +0000 (23:30 +0000)
* src/paste.c (main): Use our styled wrapper for quotearg_colon().
* cfg.mk (sc_prohibit-quotearg): A new syntax check to avoid
future uses of unstyled quotearg to one of the internal slots,
and thus destined for diagnostic output.

cfg.mk
src/paste.c

diff --git a/cfg.mk b/cfg.mk
index 78f19fa5608ed50a22f171227fd60b5786b4559f..d6c4c9f6182e6c492185aaa3ac3d20336a5aea5c 100644 (file)
--- a/cfg.mk
+++ b/cfg.mk
@@ -218,6 +218,17 @@ sc_error_shell_always_quotes:
               exit 1; }  \
          || :
 
+# Avoid unstyled quoting to internal slots and thus destined for diagnostics
+# as that can leak unescaped control characters to the output, when using
+# the default "literal" quoting style.
+# Instead use quotef(), or quoteaf() or in edge cases quotearg_n_style_colon().
+# A more general PCRE would be @prohibit='quotearg_.*(?!(style|buffer))'
+sc_prohibit-quotearg:
+       @prohibit='quotearg(_n)?(|_colon|_char|_mem) ' \
+       in_vc_files='\.c$$' \
+       halt='Unstyled diagnostic quoting detected' \
+         $(_sc_search_regexp)
+
 sc_sun_os_names:
        @grep -nEi \
            'solaris[^[:alnum:]]*2\.(7|8|9|[1-9][0-9])|sunos[^[:alnum:]][6-9]' \
index 761ae8d94071488ece86fef3eb5983ea9cb220c8..7021a9628d42b14b64eae1df3cbb350d9f2f34f1 100644 (file)
@@ -502,10 +502,9 @@ main (int argc, char **argv)
     {
       /* Don't use the quote() quoting style, because that would double the
          number of displayed backslashes, making the diagnostic look bogus.  */
-      set_quoting_style (NULL, c_maybe_quoting_style);
       error (EXIT_FAILURE, 0,
              _("delimiter list ends with an unescaped backslash: %s"),
-             quotearg_colon (delim_arg));
+             quotearg_n_style_colon (0, c_maybe_quoting_style, delim_arg));
     }
 
   if (!serial_merge)