From: Jakub Jelinek <jakub@redhat.com>
To: Ulrich Drepper <drepper@redhat.com>
Cc: Glibc hackers <libc-hacker@sources.redhat.com>
Subject: [PATCH] Test in stratcliff for zero length at the end of the cliff
Date: Sat, 09 May 2009 08:13:00 -0000 [thread overview]
Message-ID: <20090509082505.GG16681@sunsite.ms.mff.cuni.cz> (raw)
Hi!
With this patch we'd know that memchr on x86_64 has a problem, better
test it on all functions where we don't test it ATM and which have a length
argument and shouldn't dereference the pointer at all in that case.
2009-05-09 Jakub Jelinek <jakub@redhat.com>
* string/stratcliff.c (do_test): Test for zero length
STRNLEN, MEMCHR, STRNCPY, STPNCPY, MEMCPY, MEMPCPY and memccpy
at the end of the page.
--- libc/string/stratcliff.c.jj 2009-04-08 21:32:54.000000000 +0200
+++ libc/string/stratcliff.c 2009-05-09 10:06:22.000000000 +0200
@@ -129,10 +129,10 @@ do_test (void)
}
for (outer = nchars; outer >= MAX (0, nchars - 128); --outer)
{
- for (inner = MAX (outer, nchars - 64); inner < nchars; ++inner)
+ for (inner = MAX (outer, nchars - 64); inner <= nchars; ++inner)
{
- if (STRNLEN (&adr[outer], inner - outer + 1)
- != (size_t) (inner - outer + 1))
+ if (STRNLEN (&adr[outer], inner - outer)
+ != (size_t) (inner - outer))
{
printf ("%s flunked bounded for outer = %d, inner = %d\n",
STRINGIFY (STRNLEN), outer, inner);
@@ -225,7 +225,7 @@ do_test (void)
adr[middle] = L('T');
}
}
- for (outer = nchars - 1; outer >= MAX (0, nchars - 128); --outer)
+ for (outer = nchars; outer >= MAX (0, nchars - 128); --outer)
{
CHAR *cp = MEMCHR (&adr[outer], L('V'), nchars - outer);
@@ -279,9 +279,9 @@ do_test (void)
}
}
- /* strncpy tests */
+ /* strncpy/wcsncpy tests */
adr[nchars - 1] = L('T');
- for (outer = nchars - 1; outer >= MAX (0, nchars - 128); --outer)
+ for (outer = nchars; outer >= MAX (0, nchars - 128); --outer)
{
size_t len;
@@ -355,6 +355,24 @@ do_test (void)
}
/* stpncpy/wcpncpy test */
+ adr[nchars - 1] = L('T');
+ for (outer = nchars; outer >= MAX (0, nchars - 128); --outer)
+ {
+ size_t len;
+
+ for (len = 0; len < nchars - outer; ++len)
+ {
+ if (STPNCPY (dest, &adr[outer], len) != dest + len
+ || MEMCMP (dest, &adr[outer], len) != 0)
+ {
+ printf ("outer %s flunked for outer = %d, len = %Zd\n",
+ STRINGIFY (STPNCPY), outer, len);
+ result = 1;
+ }
+ }
+ }
+ adr[nchars - 1] = L('\0');
+
for (outer = nchars - 1; outer >= MAX (0, nchars - 128); --outer)
{
for (middle = MAX (outer, nchars - 64); middle < nchars; ++middle)
@@ -378,7 +396,7 @@ do_test (void)
}
/* memcpy/wmemcpy test */
- for (outer = nchars - 1; outer >= MAX (0, nchars - 128); --outer)
+ for (outer = nchars; outer >= MAX (0, nchars - 128); --outer)
for (inner = 0; inner < nchars - outer; ++inner)
if (MEMCPY (dest, &adr[outer], inner) != dest)
{
@@ -388,7 +406,7 @@ do_test (void)
}
/* mempcpy/wmempcpy test */
- for (outer = nchars - 1; outer >= MAX (0, nchars - 128); --outer)
+ for (outer = nchars; outer >= MAX (0, nchars - 128); --outer)
for (inner = 0; inner < nchars - outer; ++inner)
if (MEMPCPY (dest, &adr[outer], inner) != dest + inner)
{
@@ -401,7 +419,7 @@ do_test (void)
#ifndef WCSTEST
/* memccpy test */
memset (adr, '\0', nchars);
- for (outer = nchars - 1; outer >= MAX (0, nchars - 128); --outer)
+ for (outer = nchars; outer >= MAX (0, nchars - 128); --outer)
for (inner = 0; inner < nchars - outer; ++inner)
if (memccpy (dest, &adr[outer], L('\1'), inner) != NULL)
{
Jakub
reply other threads:[~2009-05-09 8:13 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20090509082505.GG16681@sunsite.ms.mff.cuni.cz \
--to=jakub@redhat.com \
--cc=drepper@redhat.com \
--cc=libc-hacker@sources.redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).