]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
build: consistently use freopen-safer
authorEric Blake <ebb9@byu.net>
Thu, 5 Nov 2009 23:48:09 +0000 (16:48 -0700)
committerEric Blake <ebb9@byu.net>
Sat, 7 Nov 2009 17:10:28 +0000 (10:10 -0700)
cat, head, ptx, shuf, tac, tail, tee, tr, and uniq used freopen
on stdout, and were potentially vulnerable.  dircolors, du, and
tsort only used it on stdin, which is unaffected by freopen_safer,
but this covers all uses for consistency.

* cfg.mk (sc_require_stdio_safer): New rule.
* gl/modules/xfreopen (Depends-on): Add freopen-safer.
* gl/lib/xfreopen.c (includes): Use stdio--.h.
* src/ptx.c (includes): Likewise.
* src/shuf.c (includes): Likewise.
* src/uniq.c (includes): Likewise.
* src/dircolors.c (includes): Likewise.
* src/du.c (includes): Likewise.
* src/tsort.c (includes): Likewise.

cfg.mk
gl/lib/xfreopen.c
gl/modules/xfreopen
src/dircolors.c
src/du.c
src/ptx.c
src/shuf.c
src/tsort.c
src/uniq.c

diff --git a/cfg.mk b/cfg.mk
index 27349d0383b18f5bc257e4e0beff37943a069f0d..03c3fcec99131500a584d3824af80a20557a2739 100644 (file)
--- a/cfg.mk
+++ b/cfg.mk
@@ -237,4 +237,16 @@ sc_prohibit_fail_0:
        msg='fail=0 initialization'                                     \
          $(_prohibit_regexp)
 
+# Ensure that "stdio--.h" is used where appropriate.
+sc_require_stdio_safer:
+       @if $(VC_LIST_EXCEPT) | grep -l '\.[ch]$$' > /dev/null; then    \
+         files=$$(grep -l '\bfreopen \?(' $$($(VC_LIST_EXCEPT)         \
+             | grep '\.[ch]$$'));                                      \
+         test -n "$$files" && grep -LE 'include "stdio--.h"' $$files   \
+             | grep . &&                                               \
+         { echo '$(ME): the above files should use "stdio--.h"'        \
+               1>&2; exit 1; } || :;                                   \
+       else :;                                                         \
+       fi
+
 include $(srcdir)/dist-check.mk
index 61091694bb34d420b0678b6f5b66551e7cdde5cc..32e68fa35c8f8cc5c95641a0fc3b761d23d6bf8d 100644 (file)
@@ -21,6 +21,7 @@
 #include "error.h"
 #include "exitfail.h"
 #include "quote.h"
+#include "stdio--.h"
 
 #include "gettext.h"
 #define _(msgid) gettext (msgid)
index 411f80bbdb8110772bfdb591596d65107f96df29..ed4ede75a48d0169b736d3be0e8d788409730268 100644 (file)
@@ -8,6 +8,7 @@ lib/xfreopen.h
 Depends-on:
 error
 exitfail
+freopen-safer
 quote
 
 configure.ac:
index f28487ea364a6b859a89a1c0867b31e21b4e2994..54139ba37970e4a385c25abceabc39737cea85f4 100644 (file)
@@ -19,7 +19,6 @@
 
 #include <sys/types.h>
 #include <getopt.h>
-#include <stdio.h>
 
 #include "system.h"
 #include "dircolors.h"
@@ -27,6 +26,7 @@
 #include "error.h"
 #include "obstack.h"
 #include "quote.h"
+#include "stdio--.h"
 #include "xstrndup.h"
 
 /* The official name of this program (e.g., no `g' prefix).  */
index bee006d04cebb67d3fe0573465d6b9708e59b895..61a9c43c42aa13c60374b4c4e1903baad57a5640 100644 (file)
--- a/src/du.c
+++ b/src/du.c
@@ -24,7 +24,6 @@
    Rewritten to use nftw, then to use fts by Jim Meyering.  */
 
 #include <config.h>
-#include <stdio.h>
 #include <getopt.h>
 #include <sys/types.h>
 #include <assert.h>
@@ -40,6 +39,7 @@
 #include "quotearg.h"
 #include "same.h"
 #include "stat-time.h"
+#include "stdio--.h"
 #include "xfts.h"
 #include "xstrtol.h"
 
index 4947a0f91d9a7b50ee6ba9a5eb14dcbb8dc89996..701fcb33f64b467ef7dd43b077ef096256d0dae5 100644 (file)
--- a/src/ptx.c
+++ b/src/ptx.c
@@ -19,7 +19,6 @@
 
 #include <config.h>
 
-#include <stdio.h>
 #include <getopt.h>
 #include <sys/types.h>
 #include "system.h"
@@ -29,6 +28,7 @@
 #include "quote.h"
 #include "quotearg.h"
 #include "regex.h"
+#include "stdio--.h"
 #include "xstrtol.h"
 
 /* The official name of this program (e.g., no `g' prefix).  */
index 0bb11abc1641b3882c1cbc5e20e2cc718651ae13..71411a437a805bd58489d0f66499bc75e471fd87 100644 (file)
@@ -19,7 +19,6 @@
 
 #include <config.h>
 
-#include <stdio.h>
 #include <sys/types.h>
 #include "system.h"
 
@@ -29,6 +28,7 @@
 #include "quotearg.h"
 #include "randint.h"
 #include "randperm.h"
+#include "stdio--.h"
 #include "xstrtol.h"
 
 /* The official name of this program (e.g., no `g' prefix).  */
index 09067f2674a0d66e377d827599bdb39cfa0556a0..cc6807a1e38c64207059291abb4c6d2f51f24361 100644 (file)
@@ -22,7 +22,6 @@
 
 #include <config.h>
 
-#include <stdio.h>
 #include <assert.h>
 #include <getopt.h>
 #include <sys/types.h>
@@ -32,6 +31,7 @@
 #include "error.h"
 #include "quote.h"
 #include "readtokens.h"
+#include "stdio--.h"
 
 /* The official name of this program (e.g., no `g' prefix).  */
 #define PROGRAM_NAME "tsort"
index 7509bfce9cd9b492673985ffcd95f19fa2874657..ac7ecac53f8929bb105f667fe0c977d001e31862 100644 (file)
@@ -18,7 +18,6 @@
 \f
 #include <config.h>
 
-#include <stdio.h>
 #include <getopt.h>
 #include <sys/types.h>
 
@@ -29,6 +28,7 @@
 #include "hard-locale.h"
 #include "posixver.h"
 #include "quote.h"
+#include "stdio--.h"
 #include "xmemcoll.h"
 #include "xstrtol.h"
 #include "memcasecmp.h"