summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Blake <ebb9@byu.net>2009-02-07 18:50:21 -0700
committerEric Blake <ebb9@byu.net>2009-02-11 13:56:34 -0700
commit5b4325856360a5d8836f13f17938b1acccd422cf (patch)
treec91bb55cb0b4ccdb346b85995f2518627afeee10
parent185b10ba33786707f6478b8315e9527151f60902 (diff)
downloadm4-5b4325856360a5d8836f13f17938b1acccd422cf.tar.gz
Stage 28b: Warn on embedded NUL in file arguments.
* m4/path.c (m4_path_search): Quote file names in message. * modules/m4.c (syscmd, include, m4_make_temp): Handle embedded NUL. * modules/gnu.c (debugfile, esyscmd): Likewise. * tests/others.at (nul character): Adjust test. * tests/builtins.at (mkdtemp, mkstemp): Likewise. * tests/null.m4: Likewise. * tests/null.out: Likewise. * tests/null.err: Likewise. Signed-off-by: Eric Blake <ebb9@byu.net>
-rw-r--r--ChangeLog15
-rw-r--r--m4/path.c7
-rw-r--r--modules/gnu.c26
-rw-r--r--modules/m4.c35
-rw-r--r--tests/builtins.at10
-rw-r--r--tests/null.errbin2045 -> 3237 bytes
-rw-r--r--tests/null.m4bin7735 -> 7703 bytes
-rw-r--r--tests/null.outbin613 -> 629 bytes
-rw-r--r--tests/others.at2
9 files changed, 72 insertions, 23 deletions
diff --git a/ChangeLog b/ChangeLog
index def85f5c..29fc9ef4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,20 @@
2009-02-11 Eric Blake <ebb9@byu.net>
+ Stage 28b: Warn on embedded NUL in file arguments.
+ Quote warning messages related to file and other NUL-terminated
+ system commands.
+ Memory impact: none.
+ Speed impact: none noticed.
+ * m4/path.c (m4_path_search): Quote file names in message.
+ * modules/m4.c (syscmd, include, m4_make_temp): Handle embedded
+ NUL.
+ * modules/gnu.c (debugfile, esyscmd): Likewise.
+ * tests/others.at (nul character): Adjust test.
+ * tests/builtins.at (mkdtemp, mkstemp): Likewise.
+ * tests/null.m4: Likewise.
+ * tests/null.out: Likewise.
+ * tests/null.err: Likewise.
+
Stage 28a: Warn on embedded NUL in numeric arguments.
Quote warning messages related to numeric parsing in order to
handle embedded NUL.
diff --git a/m4/path.c b/m4/path.c
index bf151935..c83aa214 100644
--- a/m4/path.c
+++ b/m4/path.c
@@ -1,6 +1,6 @@
/* GNU m4 -- A simple macro processor
Copyright (C) 1989, 1990, 1991, 1992, 1993, 1998, 2004, 2006, 2007,
- 2008 Free Software Foundation, Inc.
+ 2008, 2009 Free Software Foundation, Inc.
This file is part of GNU M4.
@@ -198,8 +198,9 @@ m4_path_search (m4 *context, const char *file, char **expanded_name)
if (fp != NULL)
{
m4_debug_message (context, M4_DEBUG_TRACE_PATH,
- _("path search for `%s' found `%s'"),
- file, name);
+ _("path search for %s found %s"),
+ quotearg_style (locale_quoting_style, file),
+ quotearg_n_style (1, locale_quoting_style, name));
if (expanded_name != NULL)
*expanded_name = name;
else
diff --git a/modules/gnu.c b/modules/gnu.c
index ce14532b..69d938f1 100644
--- a/modules/gnu.c
+++ b/modules/gnu.c
@@ -583,9 +583,17 @@ M4BUILTIN_HANDLER (debugfile)
m4_debug_set_output (context, me, NULL);
else if (m4_get_safer_opt (context) && !m4_arg_empty (argv, 1))
m4_error (context, 0, 0, me, _("disabled by --safer"));
- else if (!m4_debug_set_output (context, me, M4ARG (1)))
- m4_error (context, 0, errno, me, _("cannot set debug file %s"),
- quotearg_style (locale_quoting_style, M4ARG (1)));
+ else
+ {
+ const char *str = M4ARG (1);
+ size_t len = M4ARGLEN (1);
+ if (strlen (str) < len)
+ m4_warn (context, 0, me, _("argument %s truncated"),
+ quotearg_style_mem (locale_quoting_style, str, len));
+ if (!m4_debug_set_output (context, me, str))
+ m4_warn (context, errno, me, _("cannot set debug file %s"),
+ quotearg_style (locale_quoting_style, str));
+ }
}
@@ -635,6 +643,8 @@ M4BUILTIN_HANDLER (debugmode)
M4BUILTIN_HANDLER (esyscmd)
{
const m4_call_info *me = m4_arg_info (argv);
+ const char *cmd = M4ARG (1);
+ size_t len = M4ARGLEN (1);
M4_MODULE_IMPORT (m4, m4_set_sysval);
M4_MODULE_IMPORT (m4, m4_sysval_flush);
@@ -648,9 +658,12 @@ M4BUILTIN_HANDLER (esyscmd)
m4_error (context, 0, 0, me, _("disabled by --safer"));
return;
}
+ if (strlen (cmd) != len)
+ m4_warn (context, 0, me, _("argument %s truncated"),
+ quotearg_style_mem (locale_quoting_style, cmd, len));
/* Optimize the empty command. */
- if (m4_arg_empty (argv, 1))
+ if (!*cmd)
{
m4_set_sysval (0);
return;
@@ -658,11 +671,12 @@ M4BUILTIN_HANDLER (esyscmd)
m4_sysval_flush (context, false);
errno = 0;
- pin = popen (M4ARG (1), "r");
+ pin = popen (cmd, "r");
if (pin == NULL)
{
m4_error (context, 0, errno, me,
- _("cannot open pipe to command `%s'"), M4ARG (1));
+ _("cannot open pipe to command %s"),
+ quotearg_style (locale_quoting_style, cmd));
m4_set_sysval (-1);
}
else
diff --git a/modules/m4.c b/modules/m4.c
index 44e8a0ae..8ce419db 100644
--- a/modules/m4.c
+++ b/modules/m4.c
@@ -504,20 +504,27 @@ m4_sysval_flush (m4 *context, bool report)
M4BUILTIN_HANDLER (syscmd)
{
+ const m4_call_info *me = m4_arg_info (argv);
+ const char *cmd = M4ARG (1);
+ size_t len = M4ARGLEN (1);
+
if (m4_get_safer_opt (context))
{
m4_error (context, 0, 0, m4_arg_info (argv), _("disabled by --safer"));
return;
}
+ if (strlen (cmd) != len)
+ m4_warn (context, 0, me, _("argument %s truncated"),
+ quotearg_style_mem (locale_quoting_style, cmd, len));
/* Optimize the empty command. */
- if (m4_arg_empty (argv, 1))
+ if (!*cmd)
{
m4_set_sysval (0);
return;
}
m4_sysval_flush (context, false);
- m4_sysval = system (M4ARG (1));
+ m4_sysval = system (cmd);
/* FIXME - determine if libtool works for OS/2, in which case the
FUNC_SYSTEM_BROKEN section on the branch must be ported to work
around the bug in their EMX libc system(). */
@@ -672,13 +679,19 @@ include (m4 *context, int argc, m4_macro_args *argv, bool silent)
{
FILE *fp;
char *name = NULL;
+ const m4_call_info *me = m4_arg_info (argv);
+ const char *arg = M4ARG (1);
+ size_t len = M4ARGLEN (1);
- fp = m4_path_search (context, M4ARG (1), &name);
+ if (strlen (arg) != len)
+ m4_warn (context, 0, me, _("argument %s truncated"),
+ quotearg_style_mem (locale_quoting_style, arg, len));
+ fp = m4_path_search (context, arg, &name);
if (fp == NULL)
{
if (!silent)
m4_error (context, 0, errno, m4_arg_info (argv), _("cannot open %s"),
- quotearg_style (locale_quoting_style, M4ARG (1)));
+ quotearg_style (locale_quoting_style, arg));
return;
}
@@ -725,6 +738,12 @@ m4_make_temp (m4 *context, m4_obstack *obs, const m4_call_info *caller,
successful. */
assert (obstack_object_size (obs) == 0);
obstack_grow (obs, quotes->str1, quotes->len1);
+ if (strlen (pattern) < len)
+ {
+ m4_warn (context, 0, caller, _("argument %s truncated"),
+ quotearg_style_mem (locale_quoting_style, pattern, len));
+ len = strlen (pattern);
+ }
obstack_grow (obs, pattern, len);
for (i = 0; len > 0 && i < 6; i++)
if (pattern[--len] != 'X')
@@ -740,10 +759,10 @@ m4_make_temp (m4 *context, m4_obstack *obs, const m4_call_info *caller,
/* This use of _() will need to change if xgettext ever changes
its undocumented behavior of parsing both string options. */
- m4_error (context, 0, errno, caller,
- _(dir ? "cannot create directory from template `%s'"
- : "cannot create file from template `%s'"),
- pattern);
+ m4_warn (context, errno, caller,
+ _(dir ? "cannot create directory from template %s"
+ : "cannot create file from template %s"),
+ quotearg_style (locale_quoting_style, pattern));
obstack_free (obs, obstack_finish (obs));
}
else
diff --git a/tests/builtins.at b/tests/builtins.at
index f819403b..397f649c 100644
--- a/tests/builtins.at
+++ b/tests/builtins.at
@@ -1,5 +1,5 @@
# Hand crafted tests for GNU M4. -*- Autotest -*-
-# Copyright (C) 2001, 2006, 2007, 2008 Free Software Foundation, Inc.
+# Copyright (C) 2001, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
# This file is part of GNU M4.
#
@@ -713,8 +713,8 @@ dnl Check that on error, the expansion is void
AT_DATA([[in]],
[[mkdtemp(`no_such_dir/m4-fooXXXXXX')
]])
-AT_CHECK_M4([in], [1], [[
-]], [[m4:in:1: mkdtemp: cannot create directory from template `no_such_dir/m4-fooXXXXXX': No such file or directory
+AT_CHECK_M4([in], [0], [[
+]], [[m4:in:1: Warning: mkdtemp: cannot create directory from template `no_such_dir/m4-fooXXXXXX': No such file or directory
]])
dnl Check that umask has an effect. drws--S--T is okay.
@@ -742,8 +742,8 @@ dnl Check that on error, the expansion is void
AT_DATA([[in]],
[[mkstemp(`no_such_dir/m4-fooXXXXXX')
]])
-AT_CHECK_M4([in], [1], [[
-]], [[m4:in:1: mkstemp: cannot create file from template `no_such_dir/m4-fooXXXXXX': No such file or directory
+AT_CHECK_M4([in], [0], [[
+]], [[m4:in:1: Warning: mkstemp: cannot create file from template `no_such_dir/m4-fooXXXXXX': No such file or directory
]])
dnl Check that extra X are appended, but not trailing NUL
diff --git a/tests/null.err b/tests/null.err
index edad891e..01f2a8e7 100644
--- a/tests/null.err
+++ b/tests/null.err
Binary files differ
diff --git a/tests/null.m4 b/tests/null.m4
index 3d57806e..60711449 100644
--- a/tests/null.m4
+++ b/tests/null.m4
Binary files differ
diff --git a/tests/null.out b/tests/null.out
index cfb78c04..3859b239 100644
--- a/tests/null.out
+++ b/tests/null.out
Binary files differ
diff --git a/tests/others.at b/tests/others.at
index 3f123516..779fd3cc 100644
--- a/tests/others.at
+++ b/tests/others.at
@@ -430,7 +430,7 @@ $SED "s|null.m4|$abs_srcdir/null.m4|" < "$abs_srcdir/null.out" > expout
$SED "s|null.m4|$abs_srcdir/null.m4|" < "$abs_srcdir/null.err" > experr
dnl all but m4exit
-AT_CHECK_M4([-Dm4exit -I "$abs_srcdir" null.m4], [0], [expout], [experr])
+AT_CHECK_M4([-Dm4exit -I "$abs_srcdir" null.m4], [1], [expout], [experr])
dnl just m4exit
AT_CHECK_M4(["$abs_srcdir/null.m4"], [1],