This is the mail archive of the
cygwin-patches
mailing list for the Cygwin project.
Re: [PATCH] Fix possible segmentation fault in strnstr() on 64-bit systems
Hi Yaakov,
On Wed, 13 Sep 2017, 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.
Thank you for the hint. I am not subscribed to that list, neither do I
have the time to follow yet another mailing list, so maybe you want to add
the information that this "compiler warning" is in reality quite a bit
more serious?
Thanks!
Johannes