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

Yaakov Selkowitz yselkowitz@cygwin.com
Sun Sep 17 02:04:00 GMT 2017

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.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: OpenPGP digital signature
URL: <http://cygwin.com/pipermail/cygwin-patches/attachments/20170917/688acc3c/attachment.sig>

More information about the Cygwin-patches mailing list