The Wayback Machine - https://web.archive.org/web/20250520014024/https://github.com/git-for-windows/msys2-runtime/commit/874e2c8efeed9084cd065cf9ea5c0951f5afca02
Skip to content

Commit 874e2c8

Browse files
committed
Fix possible segmentation fault in strnstr() on 64-bit systems
As of f22054c (Modify strnstr.c., 2017-08-30), the strnstr() implementation was replaced by a version that segfaults (at least sometimes) on 64-bit systems. Without the _GNU_SOURCE constant defined, the prototype of memmem() is missing, and as a consequence its return type defaults to int (and GCC spits out a warning). On 64-bit systems, the int data type is too small, though, to hold a full char *, hence the upper 32-bit are cut off and bad things happen due to a bogus pointer being used to access memory. Reported as https://github.com/Alexpux/MINGW-packages/issues/2879 in the MSYS2 project. Cc: Sichen Zhao <1473996754@qq.com> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 6ac9184 commit 874e2c8

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

newlib/libc/string/strnstr.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ QUICKREF
3131
*/
3232

3333
#undef __STRICT_ANSI__
34+
#define _GNU_SOURCE
3435
#include <_ansi.h>
3536
#include <string.h>
3637

0 commit comments

Comments
 (0)