From 47e1388d6fe4a8015de8f3c5521ed851aef6a193 Mon Sep 17 00:00:00 2001 From: =?utf8?q?P=C3=A1draig=20Brady?= Date: Tue, 18 Jul 2023 18:38:42 +0100 Subject: [PATCH] maint: add syntax check to ensure safe mkstemp usage 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 | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/cfg.mk b/cfg.mk index 2d6856e153..9c399595fa 100644 --- 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'}" \ -- 2.47.2