diff options
| author | millert <> | 2010-06-02 12:20:47 +0000 |
|---|---|---|
| committer | millert <> | 2010-06-02 12:20:47 +0000 |
| commit | 9743c2689178c056bcbd01ce76a31f5de0e87e01 (patch) | |
| tree | 9abc412b8a9d305dd48c3dcee20c0455df418b10 | |
| parent | 6d950030380c78428e74f7f7487ee813fa22f116 (diff) | |
| download | openbsd-9743c2689178c056bcbd01ce76a31f5de0e87e01.tar.gz openbsd-9743c2689178c056bcbd01ce76a31f5de0e87e01.tar.bz2 openbsd-9743c2689178c056bcbd01ce76a31f5de0e87e01.zip | |
strnlen regression tests
Diffstat (limited to '')
| -rw-r--r-- | src/regress/lib/libc/strnlen/Makefile | 5 | ||||
| -rw-r--r-- | src/regress/lib/libc/strnlen/strnlentest.c | 69 |
2 files changed, 74 insertions, 0 deletions
diff --git a/src/regress/lib/libc/strnlen/Makefile b/src/regress/lib/libc/strnlen/Makefile new file mode 100644 index 0000000000..e7c74972e1 --- /dev/null +++ b/src/regress/lib/libc/strnlen/Makefile | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2010/06/02 12:20:47 millert Exp $ | ||
| 2 | |||
| 3 | PROG= strnlentest | ||
| 4 | |||
| 5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/strnlen/strnlentest.c b/src/regress/lib/libc/strnlen/strnlentest.c new file mode 100644 index 0000000000..e67e6adfb8 --- /dev/null +++ b/src/regress/lib/libc/strnlen/strnlentest.c | |||
| @@ -0,0 +1,69 @@ | |||
| 1 | /* $OpenBSD: strnlentest.c,v 1.1 2010/06/02 12:20:47 millert Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright (c) 2010 Todd C. Miller <Todd.Miller@courtesan.com> | ||
| 5 | * | ||
| 6 | * Permission to use, copy, modify, and distribute this software for any | ||
| 7 | * purpose with or without fee is hereby granted, provided that the above | ||
| 8 | * copyright notice and this permission notice appear in all copies. | ||
| 9 | * | ||
| 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 17 | */ | ||
| 18 | |||
| 19 | #include <sys/types.h> | ||
| 20 | |||
| 21 | #include <stdio.h> | ||
| 22 | #include <stdlib.h> | ||
| 23 | #include <string.h> | ||
| 24 | #include <unistd.h> | ||
| 25 | |||
| 26 | int main(int argc, char *argv[]) | ||
| 27 | { | ||
| 28 | char *buf; | ||
| 29 | int failures = 0; | ||
| 30 | size_t len, bufsize; | ||
| 31 | |||
| 32 | /* Enable malloc security options. */ | ||
| 33 | setenv("MALLOC_OPTIONS", "S", 0); | ||
| 34 | |||
| 35 | bufsize = getpagesize(); /* trigger guard pages easily */ | ||
| 36 | buf = malloc(bufsize); | ||
| 37 | if (buf == NULL) { | ||
| 38 | fprintf(stderr, "unable to allocate memory\n"); | ||
| 39 | return 1; | ||
| 40 | } | ||
| 41 | memset(buf, 'a', bufsize); | ||
| 42 | |||
| 43 | len = strnlen(buf, bufsize); | ||
| 44 | if (len != bufsize) { | ||
| 45 | fprintf(stderr, "strnlen: failed unterminated buffer test (1)"); | ||
| 46 | failures++; | ||
| 47 | } | ||
| 48 | |||
| 49 | len = strnlen(buf, bufsize / 2); | ||
| 50 | if (len != bufsize / 2) { | ||
| 51 | fprintf(stderr, "strnlen: failed unterminated buffer test (2)"); | ||
| 52 | failures++; | ||
| 53 | } | ||
| 54 | |||
| 55 | buf[bufsize - 1] = '\0'; | ||
| 56 | len = strnlen(buf, bufsize); | ||
| 57 | if (len != bufsize - 1) { | ||
| 58 | fprintf(stderr, "strnlen: failed NUL-terminated buffer test (1)"); | ||
| 59 | failures++; | ||
| 60 | } | ||
| 61 | |||
| 62 | len = strnlen(buf, (size_t)-1); | ||
| 63 | if (len != bufsize - 1) { | ||
| 64 | fprintf(stderr, "strnlen: failed NUL-terminated buffer test (2)"); | ||
| 65 | failures++; | ||
| 66 | } | ||
| 67 | |||
| 68 | return failures; | ||
| 69 | } | ||
