From: Cristian Rodríguez Date: Tue, 21 Mar 2023 19:55:15 +0000 (+0000) Subject: tests: fclose(stdin) UB X-Git-Tag: v2.39-rc2~22^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e0a12a5fbe7c8bd161baa3e40ad377a226b01254;p=thirdparty%2Futil-linux.git tests: fclose(stdin) UB The standard streams must not be closed unless it is the very last thing a program does before termination. A warning about this was added to POSIX.1-2008 and later standards. One must redirect stdin to /dev/null using freopen instead. --- diff --git a/tests/helpers/test_md5.c b/tests/helpers/test_md5.c index 8f2f686bcf..dc49d2184a 100644 --- a/tests/helpers/test_md5.c +++ b/tests/helpers/test_md5.c @@ -5,6 +5,8 @@ */ #include #include +#include +#include #include "md5.h" @@ -23,7 +25,9 @@ int main(void) ul_MD5Update( &ctx, buf, ret ); } - fclose(stdin); + if(freopen ("/dev/null", "r", stdin) == NULL) + err(EXIT_FAILURE, "stdin->null failed!"); + ul_MD5Final( digest, &ctx ); for (i = 0; i < UL_MD5LENGTH; i++) diff --git a/tests/helpers/test_sha1.c b/tests/helpers/test_sha1.c index e2a5f0199d..7cb107f875 100644 --- a/tests/helpers/test_sha1.c +++ b/tests/helpers/test_sha1.c @@ -5,6 +5,8 @@ */ #include #include +#include +#include #include "sha1.h" @@ -23,7 +25,9 @@ int main(void) ul_SHA1Update( &ctx, buf, ret ); } - fclose(stdin); + if(freopen ("/dev/null", "r", stdin) == NULL) + err(EXIT_FAILURE, "stdin->null failed!"); + ul_SHA1Final( digest, &ctx ); for (i = 0; i < UL_SHA1LENGTH; i++)