From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <199612090225.TAA06520@panda.mosberger> Date: Sun, 8 Dec 1996 19:25:28 -0700 From: David Mosberger-Tang Subject: memchr() bug Recently, I started to notice segfaults by various programs (like sendmail or amd) on the Linux/Alpha machine that I use in the department. I'm not sure what triggers the problem (I haven't seen these faults on the machines at home), but it looks like there is a bug in memchr (my fault): the Linux man-page isn't very explicit about whether _all_ of the memory area specified by a memchr() call needs to be accessible or not. The DEC Unix man page is very explicit, however: The memchr() function sequentially searches the string at the location ^^^^^^^^^^^^ pointed to by the s parameter until one of the following occurs: + The character specified by the c parameter, which is converted to an unsigned char, is encountered. + The number of characters specified by the n parameter have been copied to the string at location s. In other words, if memchr() is called with arguments that guarantee that the searched character is present in the string, then the count parameter (third parameter) can be arbitrarily large and the function must still work properly. For example, the following program must execute without a segfault: int main (int argc, char ** argv) { const char * str = ""; return memchr(str, '\0', 1000000); } Unfortunately, with libc-1.93 as it comes with RH4.0, this is not the case (i.e., the program will segfault). I appended a patch that should fix this problem. --david -- --- memchr.S-orig Sun Dec 8 19:13:30 1996 +++ memchr.S Sun Dec 8 19:13:41 1996 @@ -46,7 +46,6 @@ ldq_u t0, 0(a0) # load first quadword (a0 may be misaligned) addq a0, a2, t4 and a1, 0xff, a1 # a1 = 00000000000000ch - ldq_u t5, -1(t4) sll a1, 8, t1 # t1 = 000000000000ch00 cmpult a2, 9, t3 or t1, a1, a1 # a1 = 000000000000chch @@ -59,6 +58,7 @@ beq t3, $first_quad + ldq_u t5, -1(t4) extqh t5, a0, t5 mov a0, v0 or t6, t5, t0 # t0 = quadword starting at a0 -- To unsubscribe: send e-mail to axp-list-request@redhat.com with 'unsubscribe' as the subject. Do not send it to axp-list@redhat.com