From 6c48fe02c9be6a27407342904be1a8f1e7620d19 Mon Sep 17 00:00:00 2001 From: naddy <> Date: Wed, 11 Jul 2012 10:46:23 +0000 Subject: catch off-by-one errors in stpncpy(); ok guenther@ --- src/regress/lib/libc/Makefile | 12 ++++++------ src/regress/lib/libc/stpncpy/Makefile | 3 +++ src/regress/lib/libc/stpncpy/stpncpy_test.c | 24 ++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 6 deletions(-) create mode 100644 src/regress/lib/libc/stpncpy/Makefile create mode 100644 src/regress/lib/libc/stpncpy/stpncpy_test.c 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 @@ -# $OpenBSD: Makefile,v 1.33 2011/07/02 18:12:48 martynas Exp $ +# $OpenBSD: Makefile,v 1.34 2012/07/11 10:46:23 naddy Exp $ -SUBDIR+= _setjmp alloca atexit basename cxa-atexit db dirname fnmatch -SUBDIR+= fpclassify getaddrinfo getcap getopt_long glob hsearch longjmp -SUBDIR+= locale malloc netdb popen printf regex setjmp setjmp-signal -SUBDIR+= sigreturn sigsetjmp sprintf strerror strtod strtonum telldir time vis -SUBDIR+= orientation stdio_threading mkstemp env cephes +SUBDIR+= _setjmp alloca atexit basename cephes cxa-atexit db dirname env +SUBDIR+= fnmatch fpclassify getaddrinfo getcap getopt_long glob hsearch +SUBDIR+= longjmp locale malloc mkstemp netdb orientation popen printf +SUBDIR+= regex setjmp setjmp-signal sigreturn sigsetjmp sprintf +SUBDIR+= stdio_threading stpncpy strerror strtod strtonum telldir time vis .if (${MACHINE_ARCH} != "vax") SUBDIR+= 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 @@ +PROG=stpncpy_test + +.include 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 @@ +/* $OpenBSD: stpncpy_test.c,v 1.1 2012/07/11 10:46:23 naddy Exp $ */ + +/* + * Public domain, 2012, Christian Weisgerber + */ + +#include + +int main(void) +{ + char dst[8]; + char *src = "abcdef"; + + if (stpncpy(dst, src, 5) != dst + 5) + return 1; + if (stpncpy(dst, src, 6) != dst + 6) + return 1; + if (stpncpy(dst, src, 7) != dst + 6) + return 1; + if (stpncpy(dst, src, 8) != dst + 6) + return 1; + + return 0; +} -- cgit v1.2.3-55-g6feb