From 2836ec90229ebe85aa1e3c8f785f2b1723ba406d Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Tue, 10 Sep 2002 00:25:47 +0000 Subject: Some more strncpy checks. --- string/stratcliff.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'string/stratcliff.c') diff --git a/string/stratcliff.c b/string/stratcliff.c index f25ae0ca79..9b0e4211a6 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 , 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'; -- cgit 1.4.1