]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
build: prohibit improper use of stat and lstat
authorEric Blake <ebb9@byu.net>
Fri, 23 Oct 2009 12:06:46 +0000 (06:06 -0600)
committerEric Blake <ebb9@byu.net>
Fri, 23 Oct 2009 12:29:54 +0000 (06:29 -0600)
* cfg.mk (sc_prohibit_stat_macro_address): New rule.
* src/ln.c (do_link): Adjust comment to avoid false positive.
* src/stat.c (do_stat): Likewise.
* src/touch.c (main): Likewise.

cfg.mk
src/ln.c
src/stat.c
src/touch.c

diff --git a/cfg.mk b/cfg.mk
index 807d3c9c4e1fe14781abfcd40832e53135d64cad..1e5108b2d4ceabefa6ee3f657bde33b6a3a9e075 100644 (file)
--- a/cfg.mk
+++ b/cfg.mk
@@ -197,6 +197,12 @@ sc_prohibit_readlink:
        msg='do not use readlink(at); use via xreadlink or areadlink*'  \
          $(_prohibit_regexp)
 
+# Don't use address of "stat" or "lstat" functions
+sc_prohibit_stat_macro_address:
+       @re='\<l?stat '':|&l?stat\>'                                    \
+       msg='stat() and lstat() may be function-like macros'            \
+         $(_prohibit_regexp)
+
 # Ensure that date's --help output stays in sync with the info
 # documentation for GNU strftime.  The only exception is %N,
 # which date accepts but GNU strftime does not.
index 4f75c1919ca8f3fac4854e72d7840443ad32f65e..197a8faec6fb14566cee29dca513828e7d50f37f 100644 (file)
--- a/src/ln.c
+++ b/src/ln.c
@@ -138,7 +138,7 @@ do_link (const char *source, const char *dest)
     {
        /* Which stat to use depends on whether linkat will follow the
           symlink.  We can't use the shorter
-          (logical ? stat : lstat) (source, &source_stats)
+          (logical?stat:lstat) (source, &source_stats)
           since stat might be a function-like macro.  */
       if ((logical ? stat (source, &source_stats)
            : lstat (source, &source_stats))
index d3e16d70556fe417c3c5e8cba354810a0518fb8e..ae5491154e9057c851a5ac4f92d1a0b3b14642f3 100644 (file)
@@ -903,7 +903,7 @@ do_stat (char const *filename, bool terse, char const *format)
         }
     }
   /* We can't use the shorter
-     (follow_links ? stat : lstat) (filename, &statbug)
+     (follow_links?stat:lstat) (filename, &statbug)
      since stat might be a function-like macro.  */
   else if ((follow_links
             ? stat (filename, &statbuf)
index d44bd2739de93164bb77e2bd2ec10fabbf0029e5..11d73ce6c42f3b8fec87b250ef855cc2fb9b44eb 100644 (file)
@@ -348,7 +348,7 @@ main (int argc, char **argv)
   if (use_ref)
     {
       struct stat ref_stats;
-      /* Don't use (no_dereference ? lstat : stat) (args), since stat
+      /* Don't use (no_dereference?lstat:stat) (args), since stat
          might be an object-like macro.  */
       if (no_dereference ? lstat (ref_file, &ref_stats)
           : stat (ref_file, &ref_stats))