]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
maint: add syntax check to ensure safe mkstemp usage
authorPádraig Brady <P@draigBrady.com>
Tue, 18 Jul 2023 17:38:42 +0000 (18:38 +0100)
committerPádraig Brady <P@draigBrady.com>
Tue, 18 Jul 2023 17:59:10 +0000 (18:59 +0100)
One needs to include stdlib--.h if using mkstemp()
lest one hits esoteric bugs with closed stdin etc.

* cfg.mk (sc_require_stdlib_safer): Add a new syntax check.
(sc_require_stdio_safer): Fix this; broken since commit fa7ed969c3.

cfg.mk

diff --git a/cfg.mk b/cfg.mk
index 2d6856e153b8a8c7236c9fbb0ef8011e54f6f9ef..9c399595fa72e6fa7876505f71df943911a9b9d9 100644 (file)
--- a/cfg.mk
+++ b/cfg.mk
@@ -561,7 +561,7 @@ sc_prohibit_short_facl_mode_spec:
 # 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 '$(begword)freopen \?(' $$($(VC_LIST_EXCEPT) \
+         files=$$(grep -El '$(begword)freopen ?\(' $$($(VC_LIST_EXCEPT)\
              | grep '\.[ch]$$'));                                      \
          test -n "$$files" && grep -LE 'include "stdio--.h"' $$files   \
              | grep . &&                                               \
@@ -570,6 +570,18 @@ sc_require_stdio_safer:
        else :;                                                         \
        fi
 
+# Ensure that "stdlib--.h" is used where appropriate.
+sc_require_stdlib_safer:
+       @if $(VC_LIST_EXCEPT) | grep -l '\.[ch]$$' > /dev/null; then    \
+         files=$$(grep -El '$(begword)mkstemp ?\(' $$($(VC_LIST_EXCEPT)\
+             | grep '\.[ch]$$'));                                      \
+         test -n "$$files" && grep -LE 'include "stdlib--.h"' $$files  \
+             | grep . &&                                               \
+         { echo '$(ME): the above files should use "stdlib--.h"'       \
+               1>&2; exit 1; } || :;                                   \
+       else :;                                                         \
+       fi
+
 sc_prohibit_perl_hash_quotes:
        @prohibit="\{'[A-Z_]+' *[=}]"                                   \
        halt="in Perl code, write \$$hash{KEY}, not \$$hash{'K''EY'}"   \