[PATCH] Fix possible segmentation fault in strnstr() on 64-bit systems

cyg Simple cygsimple@gmail.com
Sun Sep 17 02:04:00 GMT 2017

On 9/13/2017 5:55 PM, Yaakov Selkowitz wrote:
> On 2017-09-13 10:44, Johannes Schindelin wrote:
>> As of f22054c94d (Modify strnstr.c., 2017-08-30), the strnstr()
>> implementation was replaced by a version that segfaults (at least
>> sometimes) on 64-bit systems.
>> The reason: the new implementation uses memmem(), and the prototype of
>> memmem() is missing because the _GNU_SOURCE constant is not defined
>> before including <string.h>. 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.
> As this is part of newlib, the proper place for this is on the newlib
> list.  Others have already proposed similar patches, so please feel free
> to follow the discussion there.

This begs the question as to why _GNU_SOURCE isn't defined by default
for Cygwin?

cyg Simple

More information about the Cygwin-patches mailing list