m4-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: branch-1_4 maketemp cleanup


From: Eric Blake-1
Subject: Re: branch-1_4 maketemp cleanup
Date: Mon, 23 Oct 2006 11:15:37 -0700 (PDT)

> And while I was at it, I implemented the mkstemp macro, which is the Austin 
> group's recommended solution to my aardvark that the POSIX semantics of 
> maketemp are insecure.

And in the process, broke builds with --disable-assert, which was creating a
builtin named "mkstemp_safer".  Further investigation shows that we were
only picking up the gnulib "stdlib--.h" when asserts were disabled, which is
a bug for when asserts are enabled.  Once that is fixed, the bug when
asserts
were disabled is then also present with asserts; namely, we generate our
builtin list using the preprocessor to concatenate tokens, but the
concatenation
expands the token if that token is also a macro.  Had we manually listed
{builtin_mkstemp, "mkstemp"} rather than going for the cute trick of
BUILTIN(mkstemp) fed through
#define BUILTIN(name) {CONC(builtin_,name), STR(name)}, this would
not have happened.  Is there any good way to tell the C preprocessor
not to expand a token before concatenation, when that token will be
passed through multiple preprocessor macro expansions?

For now, I am just providing the following hack to fix mkstemp again.
However, we are at risk of this happening again for any of the M4 builtins
that share a name with a library function, seeing as how those library
functions can be provided as macros, but we do not want those macros
expanded when forming the builtin_* name of our builtin function.  I like
the idea of using the preprocessor to reduce typing and keeping the list
of builtins consistent from a single listing, but is it worth the risk of
problems encountered with undesired macro expansion when
concatenating tokens?

2006-10-23  Eric Blake  <address@hidden>

        * modules/m4.c (includes): Use safe headers even when configured
        with --enable-assert.
        (m4_builtin_table, m4_make_temp): Work around fact that mkstemp is
        #defined as mkstemp_safer.

Index: modules/m4.c
===================================================================
RCS file: /sources/m4/m4/modules/m4.c,v
retrieving revision 1.85
diff -u -r1.85 m4.c
--- modules/m4.c        21 Oct 2006 22:15:52 -0000      1.85
+++ modules/m4.c        23 Oct 2006 18:11:29 -0000
@@ -21,8 +21,9 @@
 
 #include <assert.h>
 #include <errno.h>
-#include <stdlib.h>
-#include <unistd.h>
+
+#include "stdlib--.h"
+#include "unistd--.h"
 
 #if HAVE_SYS_WAIT_H
 # include <sys/wait.h>
@@ -56,6 +57,10 @@
 extern void m4_make_temp     (m4 *context, m4_obstack *obs, const char
*macro,
                              const char *name, bool dir);
 
+/* stdlib--.h defines mkstemp to a safer replacement, but this
+   interferes with our preprocessor table of builtin definitions.  */
+#undef mkstemp
+
 /* Maintain each of the builtins implemented in this modules along
    with their details in a single table for easy maintenance.
 
@@ -706,7 +711,7 @@
   if (dir)
     fd = mkdtemp (obstack_base (obs)) ? 0 : -1;
   else
-    fd = mkstemp (obstack_base (obs));
+    fd = mkstemp_safer (obstack_base (obs));
   if (fd < 0)
     {
       /* This use of _() will need to change if xgettext ever changes

-- 
View this message in context: 
http://www.nabble.com/branch-1_4-maketemp-cleanup-tf2481822.html#a6958544
Sent from the Gnu - M4 - Patches mailing list archive at Nabble.com.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]