summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornaddy <>2012-07-11 10:46:23 +0000
committernaddy <>2012-07-11 10:46:23 +0000
commit6c48fe02c9be6a27407342904be1a8f1e7620d19 (patch)
tree1a80b9d610bafa8678620c1004774a4bac9764a4
parente1fe34b2d493d33174e80455cc4c8962feae4333 (diff)
downloadopenbsd-6c48fe02c9be6a27407342904be1a8f1e7620d19.tar.gz
openbsd-6c48fe02c9be6a27407342904be1a8f1e7620d19.tar.bz2
openbsd-6c48fe02c9be6a27407342904be1a8f1e7620d19.zip
catch off-by-one errors in stpncpy(); ok guenther@
-rw-r--r--src/regress/lib/libc/Makefile12
-rw-r--r--src/regress/lib/libc/stpncpy/Makefile3
-rw-r--r--src/regress/lib/libc/stpncpy/stpncpy_test.c24
3 files changed, 33 insertions, 6 deletions
diff --git a/src/regress/lib/libc/Makefile b/src/regress/lib/libc/Makefile
index 24749b95b4..a0b950033e 100644
--- a/src/regress/lib/libc/Makefile
+++ b/src/regress/lib/libc/Makefile
@@ -1,10 +1,10 @@
1# $OpenBSD: Makefile,v 1.33 2011/07/02 18:12:48 martynas Exp $ 1# $OpenBSD: Makefile,v 1.34 2012/07/11 10:46:23 naddy Exp $
2 2
3SUBDIR+= _setjmp alloca atexit basename cxa-atexit db dirname fnmatch 3SUBDIR+= _setjmp alloca atexit basename cephes cxa-atexit db dirname env
4SUBDIR+= fpclassify getaddrinfo getcap getopt_long glob hsearch longjmp 4SUBDIR+= fnmatch fpclassify getaddrinfo getcap getopt_long glob hsearch
5SUBDIR+= locale malloc netdb popen printf regex setjmp setjmp-signal 5SUBDIR+= longjmp locale malloc mkstemp netdb orientation popen printf
6SUBDIR+= sigreturn sigsetjmp sprintf strerror strtod strtonum telldir time vis 6SUBDIR+= regex setjmp setjmp-signal sigreturn sigsetjmp sprintf
7SUBDIR+= orientation stdio_threading mkstemp env cephes 7SUBDIR+= stdio_threading stpncpy strerror strtod strtonum telldir time vis
8 8
9.if (${MACHINE_ARCH} != "vax") 9.if (${MACHINE_ARCH} != "vax")
10SUBDIR+= ieeefp 10SUBDIR+= ieeefp
diff --git a/src/regress/lib/libc/stpncpy/Makefile b/src/regress/lib/libc/stpncpy/Makefile
new file mode 100644
index 0000000000..9333934da6
--- /dev/null
+++ b/src/regress/lib/libc/stpncpy/Makefile
@@ -0,0 +1,3 @@
1PROG=stpncpy_test
2
3.include <bsd.regress.mk>
diff --git a/src/regress/lib/libc/stpncpy/stpncpy_test.c b/src/regress/lib/libc/stpncpy/stpncpy_test.c
new file mode 100644
index 0000000000..63b7d25e53
--- /dev/null
+++ b/src/regress/lib/libc/stpncpy/stpncpy_test.c
@@ -0,0 +1,24 @@
1/* $OpenBSD: stpncpy_test.c,v 1.1 2012/07/11 10:46:23 naddy Exp $ */
2
3/*
4 * Public domain, 2012, Christian Weisgerber <naddy@openbsd.org>
5 */
6
7#include <string.h>
8
9int main(void)
10{
11 char dst[8];
12 char *src = "abcdef";
13
14 if (stpncpy(dst, src, 5) != dst + 5)
15 return 1;
16 if (stpncpy(dst, src, 6) != dst + 6)
17 return 1;
18 if (stpncpy(dst, src, 7) != dst + 6)
19 return 1;
20 if (stpncpy(dst, src, 8) != dst + 6)
21 return 1;
22
23 return 0;
24}