aboutsummaryrefslogtreecommitdiff
path: root/string
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2002-09-10 00:25:47 +0000
committerUlrich Drepper <drepper@redhat.com>2002-09-10 00:25:47 +0000
commit2836ec90229ebe85aa1e3c8f785f2b1723ba406d (patch)
treee3850887f83c60d16b146e6205a5ccae87619b35 /string
parent64ca3f329b3232d6926a44fa10b6e9f1cb92687d (diff)
downloadglibc-2836ec90229ebe85aa1e3c8f785f2b1723ba406d.zip
glibc-2836ec90229ebe85aa1e3c8f785f2b1723ba406d.tar.gz
glibc-2836ec90229ebe85aa1e3c8f785f2b1723ba406d.tar.bz2
Some more strncpy checks.
Diffstat (limited to 'string')
-rw-r--r--string/stratcliff.c32
1 files changed, 30 insertions, 2 deletions
diff --git a/string/stratcliff.c b/string/stratcliff.c
index f25ae0c..9b0e421 100644
--- a/string/stratcliff.c
+++ b/string/stratcliff.c
@@ -1,5 +1,5 @@
/* Test for string function add boundaries of usable memory.
- Copyright (C) 1996, 1997, 1999, 2000, 2001 Free Software Foundation, Inc.
+ Copyright (C) 1996,1997,1999,2000,2001,2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
@@ -192,7 +192,25 @@ main (int argc, char *argv[])
}
}
- /* strncpy test */
+ /* strncpy tests */
+ adr[size-1] = 'T';
+ for (outer = size - 1; outer >= MAX (0, size - 128); --outer)
+ {
+ size_t len;
+
+ for (len = 0; len < size - outer; ++len)
+ {
+ if (strncpy (dest, &adr[outer], len) != dest
+ || memcmp (dest, &adr[outer], len) != 0)
+ {
+ printf ("outer strncpy flunked for outer = %d, len = %Zd\n",
+ outer, len);
+ result = 1;
+ }
+ }
+ }
+ adr[size-1] = '\0';
+
for (outer = size - 1; outer >= MAX (0, size - 128); --outer)
{
for (inner = MAX (outer, size - 64); inner < size; ++inner)
@@ -213,6 +231,16 @@ main (int argc, char *argv[])
outer, inner, len);
result = 1;
}
+ if (strncpy (dest + 1, &adr[outer], len) != dest + 1
+ || memcmp (dest + 1, &adr[outer],
+ MIN (inner - outer, len)) != 0
+ || (inner - outer < len
+ && strlen (dest + 1) != (inner - outer)))
+ {
+ printf ("strncpy+1 flunked for outer = %d, inner = %d, len = %Zd\n",
+ outer, inner, len);
+ result = 1;
+ }
}
adr[inner] = 'T';