This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
Re: segfault in test-strcmp
- From: Geoff Keating <geoffk at geoffk dot org>
- To: Roland McGrath <roland at redhat dot com>
- Cc: Jakub Jelinek <jakub at redhat dot com>, libc-alpha at sources dot redhat dot com
- Date: 08 Nov 2002 12:08:58 -0800
- Subject: Re: segfault in test-strcmp
- References: <200211080244.gA82i4N32259@magilla.sf.frob.com>
Roland McGrath <roland@redhat.com> writes:
> I looked at the test-strchr crash before the test-strcmp one, but I suspect
> the problem is similar. The sysdeps/powerpc/powerpc32/strchr.S code is
> accessing the word following the word containing the search character.
> This faults because the test string is aligned on the end of a page so that
> the following word cannot be accessed (this happens on iteration 157 in
> test-strchr with no srandom). The test program is arguably invoking
> undefined behavior, because the string is actually not terminated: the
> final word of the page contains the search character and three other
> nonzero bytes. So a stupid but valid implementation of strchr that called
> strlen would crash.
Yes, ISO C requires that strings be zero-terminated (C99 section 7.1.1
paragraph 1), and requires that the argument to strchr be a string
(section 7.21.5.2 paragraph 2). For non-zero-terminated character
arrays, use memchr instead.
> It may be quicker for someone who knows powerpc assembly better than I do
> to try to fix this.
I think the testcase should be fixed instead.
--
- Geoffrey Keating <geoffk@geoffk.org>