If gets() is used without _FORTIFY_SOURCE, a warning should IMO be printed regardless of __MINGW_MSVC_COMPAT_WARNINGS etc.

It is the same warning text used if _FORTIFY_SOURCE is enabled and gets() is called instead of __gets_chk().

More strict handling would also be possible, but I'm not sure whether one of these should be added: - Fail with attribute(error(...)) if gets() is used and C11/C++14 is enabled as these standards finally removed this function. - Fail with attribute(error(...)) if _FORTIFY_SOURCE is enabled and gets() is called instead of __gets_chk().

--
Regards,
Christian

From 87d0961909d096a0fb23d24abeddc0cd7e83fdab Mon Sep 17 00:00:00 2001
From: Christian Franke <[email protected]>
Date: Tue, 14 Feb 2023 13:00:05 +0100
Subject: [PATCH] headers: Always warn if gets() is used

Signed-off-by: Christian Franke <[email protected]>
---
 mingw-w64-headers/crt/stdio.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/mingw-w64-headers/crt/stdio.h b/mingw-w64-headers/crt/stdio.h
index 56cd26ddb..d37e2e397 100644
--- a/mingw-w64-headers/crt/stdio.h
+++ b/mingw-w64-headers/crt/stdio.h
@@ -688,7 +688,8 @@ int vsnprintf (char *__stream, size_t __n, const char 
*__format, __builtin_va_li
   int __cdecl getc(FILE *_File);
   int __cdecl getchar(void);
   _CRTIMP int __cdecl _getmaxstdio(void);
-  char *__cdecl gets(char *_Buffer) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
+  char *__cdecl gets(char *_Buffer)
+    __attribute__((__warning__("Using gets() is always unsafe - use fgets() 
instead")));
   int __cdecl _getw(FILE *_File);
 #ifndef _CRT_PERROR_DEFINED
 #define _CRT_PERROR_DEFINED
-- 
2.38.1

_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to