Skip to contentSkip to conversation

segv at strcmp

DISCUSSION umut aymakoglu 4 participants 4 messages Dec 24, 2003 – Dec 25, 2003

lore
Share & tools
lore
#0 lore raw

Hi -

We have hit a problem with strcmp() on UnitedLinux 1.0 with kernel: 2.4.19 and glibc: 2.2.5.
I am wondering if anybody has seen something like it or knows if already there is a patch. I do not have a small repro but i will try to explain:

The segv happens at memcmp() at a line like:
'strcmp(x, "this is 24 chars long")' where x is a char pointer with a length of 7 and the constant has a length of 24. x is located at the first 8 bytes of the last 16 bytes at the end of a non-contiguous shared memory segment. memcmp() segvs when it tries to load 8 bytes from the "r19" register which initially has the address of x and points to the end of the segment when the segv happens.

any help would be appreciated,
thanks,
Umut

__________________________________
Do you Yahoo!?
New Yahoo! Photos - easier uploading and sharing.
http://photos.yahoo.com/

#1 lore raw
Quoted 6 lines · umut aymakoglu

The segv happens at memcmp() at a line like: 'strcmp(x, "this is 24 chars long")' where x is a char pointer with a length of 7 and the constant has a length of 24. x is located at the first 8 bytes of the last 16 bytes at the end of a non-contiguous shared memory segment. memcmp() segvs when it tries to load 8 bytes from the "r19" register which initially has the address of x and points to the end of the segment when the segv happens.

So are you calling strcmp() or memcmp() ? If you are calling strcmp(), it sounds like the "last 16 bytes" are not null-terminated to be a valid string and the strcmp() is running off the end of the memory segment which causes it to try address memory to which it doesn't have access. If you're calling memcmp() with a length longer than 16 then it is also running off the end of the segment.

--
Jeff Woods <[email protected]>

#2 lore raw
In reply to umut aymakoglu
Quoted 6 lines

We have hit a problem with strcmp() on UnitedLinux 1.0 with kernel: 2.4.19 and glibc: 2.2.5.
I am wondering if anybody has seen something like it or knows if already there is a patch. I do not have a small repro but i will try to explain:

Quoted 9 lines

The segv happens at memcmp() at a line like:
'strcmp(x, "this is 24 chars long")' where x is a char pointer with a length of 7 and the constant has a length of 24. x is located at the first 8 bytes of the last 16 bytes at the end of a non-contiguous shared memory segment. memcmp() segvs when it tries to load 8 bytes from the "r19" register which initially has the address of x and points to the end of the segment when the segv happens.

Sounds like your compiler converted the strcmp(str, const_str) into memcmp(str, const_str, strlen(const_str)) ... and then the memcmp fell off the end of the page.

What version of gcc are you using, and what arguments are you passing to gcc?

-Tony

#3 lore raw
In reply to umut aymakoglu
Quoted 6 lines · umut aymakoglu

We have hit a problem with strcmp() on UnitedLinux 1.0 with kernel: 2.4.19 and glibc: 2.2.5.
I am wondering if anybody has seen something like it or knows if already there is a patch. I do not have a small repro but i will try to explain:

Quoted 9 lines

The segv happens at memcmp() at a line like:
'strcmp(x, "this is 24 chars long")' where x is a char pointer with a length of 7 and the constant has a length of 24. x is located at the first 8 bytes of the last 16 bytes at the end of a non-contiguous shared memory segment. memcmp() segvs when it tries to load 8 bytes from the "r19" register which initially has the address of x and points to the end of the segment when the segv happens.

I met the similar scenario for strchr(), it was fixed after I explicitly adding a #include <string.h>.

Quoted 16 lines

any help would be appreciated,
thanks,
Umut

__________________________________
Do you Yahoo!?
New Yahoo! Photos - easier uploading and sharing.
http://photos.yahoo.com/
-
To unsubscribe from this list: send the line "unsubscribe linux-ia64" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

FLAGS (\Seen \Recent))

Signature · 15 lines
-----------------------------------------------------------------
Opinions expressed are those of the author and do not represent
Intel Corp.

Zhu Yi (Chuyee)
Intel China Software Lab (ICSL)
22nd Floor, ShanghaiMart Tower No. 2299 Yan'an Road(West)
Shanghai 200336, PRC
Tel: 8621-52574545-1261
Fax: 8621-62360011

GnuPG v1.0.6 (GNU/Linux)
http://cn.geocities.com/chewie_chuyee/gpg.txt or
$ gpg --keyserver wwwkeys.pgp.net --recv-keys 71C34820
1024D/71C34820 C939 2B0B FBCE 1D51 109A  55E5 8650 DB90 71C3 4820