X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=tests%2Ftest-strerror_r.c;h=ec43aef9ade367164f3610cf8c77b4820b728792;hb=23eecb48e39afd0d267d64d40ba6bf97aa865e13;hp=1f23ba8f8221bc29240d0843d2bf0c296809f076;hpb=3a3fe58b91a00ba3cafd960a2e2355c842448e47;p=gnulib.git
diff --git a/tests/test-strerror_r.c b/tests/test-strerror_r.c
index 1f23ba8f8..ec43aef9a 100644
--- a/tests/test-strerror_r.c
+++ b/tests/test-strerror_r.c
@@ -1,5 +1,5 @@
/* Test of strerror_r() function.
- Copyright (C) 2007-2011 Free Software Foundation, Inc.
+ Copyright (C) 2007-2013 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -12,8 +12,7 @@
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software Foundation,
- Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+ along with this program; if not, see . */
#include
@@ -66,6 +65,7 @@ main (void)
ASSERT (buf[0]);
ASSERT (errno == 0);
ASSERT (strstr (buf, "nknown") == NULL);
+ ASSERT (strstr (buf, "ndefined") == NULL);
/* Test results with out-of-range errnum and enough room. POSIX
allows an empty string on success, and allows an unchanged buf on
@@ -84,10 +84,13 @@ main (void)
EINVAL for out-of-range values. On error, POSIX permits buf to
be empty, unchanged, or unterminated, but these are not useful,
so we guarantee NUL-terminated truncated contents for all but
- size 0. http://austingroupbugs.net/view.php?id=398 */
+ size 0. http://austingroupbugs.net/view.php?id=398. Also ensure
+ that no out-of-bounds writes occur. */
{
int errs[] = { EACCES, 0, -3, };
int j;
+
+ buf[sizeof buf - 1] = '\0';
for (j = 0; j < SIZEOF (errs); j++)
{
int err = errs[j];
@@ -97,10 +100,11 @@ main (void)
strerror_r (err, buf2, sizeof buf2);
len = strlen (buf2);
+ ASSERT (len < sizeof buf);
for (i = 0; i <= len; i++)
{
- strcpy (buf, "BADFACE");
+ memset (buf, '^', sizeof buf - 1);
errno = 0;
ret = strerror_r (err, buf, i);
ASSERT (errno == 0);
@@ -108,13 +112,12 @@ main (void)
ASSERT (ret == ERANGE || ret == EINVAL);
else
ASSERT (ret == ERANGE);
- if (i == 0)
- ASSERT (strcmp (buf, "BADFACE") == 0);
- else
+ if (i)
{
ASSERT (strncmp (buf, buf2, i - 1) == 0);
ASSERT (buf[i - 1] == '\0');
}
+ ASSERT (strspn (buf + i, "^") == sizeof buf - 1 - i);
}
strcpy (buf, "BADFACE");