diff options
author | 2012-07-11 10:46:23 +0000 | |
---|---|---|
committer | 2012-07-11 10:46:23 +0000 | |
commit | a4068d978a66817a0040333fa9cf93bfa5fc2823 (patch) | |
tree | 0d8cc8671e214ec27420aae01ae391d4db46a1fb | |
parent | fix an off-by-one error where the return value would point to the (diff) | |
download | wireguard-openbsd-a4068d978a66817a0040333fa9cf93bfa5fc2823.tar.xz wireguard-openbsd-a4068d978a66817a0040333fa9cf93bfa5fc2823.zip |
catch off-by-one errors in stpncpy(); ok guenther@
-rw-r--r-- | regress/lib/libc/Makefile | 12 | ||||
-rw-r--r-- | regress/lib/libc/stpncpy/Makefile | 3 | ||||
-rw-r--r-- | regress/lib/libc/stpncpy/stpncpy_test.c | 24 |
3 files changed, 33 insertions, 6 deletions
diff --git a/regress/lib/libc/Makefile b/regress/lib/libc/Makefile index 24749b95b4c..a0b950033e7 100644 --- a/regress/lib/libc/Makefile +++ b/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/regress/lib/libc/stpncpy/Makefile b/regress/lib/libc/stpncpy/Makefile new file mode 100644 index 00000000000..9333934da6e --- /dev/null +++ b/regress/lib/libc/stpncpy/Makefile @@ -0,0 +1,3 @@ +PROG=stpncpy_test + +.include <bsd.regress.mk> diff --git a/regress/lib/libc/stpncpy/stpncpy_test.c b/regress/lib/libc/stpncpy/stpncpy_test.c new file mode 100644 index 00000000000..63b7d25e530 --- /dev/null +++ b/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 <naddy@openbsd.org> + */ + +#include <string.h> + +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; +} |