my strstr is broken
Allin Cottrell
cottrell@wfu.edu
Tue Sep 11 12:58:00 GMT 2018
On Tue, 11 Sep 2018, Michael Brunnbauer wrote:
> hi all,
>
> I assume it cannot be reproduced and is limited to my build?
>
> Any ideas/hints for me? The fact that the needle is 513 bytes and occurs at
> an offset of 513 bytes in the haystack should provide some clue?
>
> cu,
> brunni
>
> On Mon, Sep 10, 2018 at 04:47:52PM +0200, Michael Brunnbauer wrote:
>>
>> can someone reproduce this with 2.28 (program exits with return code 255)?
>>
>> -----------------------------------------------------------
>> #include <string.h>
>>
>> int main (void)
>> {
>> char* i = " xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
>> char* n = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
>> if (!strstr(i,n)) return 255;
>> return 0;
>> }
Since it's difficult to verify your long strings in email I tried the
following variant of your test:
#include <string.h>
#include <stdio.h>
int main (void)
{
char h[513*2+1];
char n[513+1];
char *s;
int i;
for (i=0; i<513; i++) {
n[i] = 'x';
h[i] = ' ';
h[i+513] = 'x';
}
n[513] = '\0';
h[513*2] = '\0';
printf("h=\"%s\"\n", h);
printf("n=\"%s\"\n", n);
s = strstr(h, n);
printf("s = %p\n", (void *) s);
printf("strcmp(n, s) = %d\n", strcmp(s, n));
return 0;
}
Compiled with gcc 8.2.1 20180831 (Arch) the output is
s = 0x7ffe8771ae51
strcmp(n, s) = 0
--
Allin Cottrell
Department of Economics
Wake Forest University, NC
More information about the Libc-help
mailing list