JonY wrote:
On 8/24/19 6:50 PM, Christian Franke wrote:
Hi,

packages from Linux and *BSD distros are often build with
-D_FORTIFY_SOURCE=2 set by default. This enables buffer overflow checks
for functions like strcpy() if buffer size is known at compile time.

Attached is an experimental patch that adds some _FORTIFY_SOURCE support
to Mingw-w64 string.h and stdio.h. The test program shows the code
modification as comments. I verified this in assembly output
x86_64-w64-mingw-gcc and ...-g++.

Supported functions: memcpy(), memset(), strcpy(), strcat(), strncpy(),
strncat(), snprintf(), vsnprintf(),
and for __USE_MINGW_ANSI_STDIO only: sprintf(), vsprintf(), snwprintf(),
vsnwprintf(),

The GCC __builtin___*_chk() functions are not used for now because the
required _*_chk() library functions are not available.

The patch also shows how varargs *printf() wrappers could be rewritten
if compiler supports __builtin_va_arg_pack().

Thanks for any comment.

Thanks for the interesting patch, do you know what needs to be changed
in GCC?



Possibly nothing. Works out of the box with  *-w64-mingw32-gcc and -g++ 7.4.0 from current Cygwin package.



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

Reply via email to