From e0a12a5fbe7c8bd161baa3e40ad377a226b01254 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Cristian=20Rodr=C3=ADguez?= Date: Tue, 21 Mar 2023 19:55:15 +0000 Subject: [PATCH] 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. --- tests/helpers/test_md5.c | 6 +++++- tests/helpers/test_sha1.c | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) 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++) -- 2.47.3