diff options
author | Philip Guenther <guenther@cvs.openbsd.org> | 2013-03-12 15:01:20 +0000 |
---|---|---|
committer | Philip Guenther <guenther@cvs.openbsd.org> | 2013-03-12 15:01:20 +0000 |
commit | f9e6a48483c32a177e2e7f6710b5f51a5053be88 (patch) | |
tree | 3f140201c23cf93cc64ef0595dda4e59df789a57 /regress | |
parent | ea2d4bf57cb3882b5d8c3803b63071e71cdeaa82 (diff) |
Add check that mkstemp() fails with EINVAL if the string has fewer than
6 Xs
Diffstat (limited to 'regress')
-rw-r--r-- | regress/lib/libc/mkstemp/mkstemp_test.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/regress/lib/libc/mkstemp/mkstemp_test.c b/regress/lib/libc/mkstemp/mkstemp_test.c index fd133d83689..ef973b061b6 100644 --- a/regress/lib/libc/mkstemp/mkstemp_test.c +++ b/regress/lib/libc/mkstemp/mkstemp_test.c @@ -9,17 +9,19 @@ */ #include <sys/param.h> +#include <sys/mman.h> +#include <sys/stat.h> #include <err.h> +#include <errno.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <sys/mman.h> -#include <sys/stat.h> #include <unistd.h> #define MAX_TEMPLATE_LEN 10 #define MAX_TRIES 100 +#define MIN_Xs 6 #define SUFFIX ".suff" #define SLEN (sizeof SUFFIX - 1) @@ -38,8 +40,15 @@ check(int fd, char const *path, char const *prefix, size_t plen, struct stat sb, fsb; char const *p; + if (tlen < MIN_Xs) { + if (fd >= 0) + errx(1, "mkstemp(%s) succeed with too few Xs", path); + if (errno != EINVAL) + err(1, "mkstemp(%s) failed with wrong errno", path); + return 1; + } if (fd < 0) - err(1, "mkstemp"); + err(1, "mkstemp(%s)", path); if (stat(path, &sb)) err(1, "stat(%s)", path); if (fstat(fd, &fsb)) @@ -120,7 +129,7 @@ main(void) p += pg; i = MAX_TEMPLATE_LEN + 1; - while (i-- > 1) { + while (i-- > 0) { /* try first at the start of a page, no prefix */ try_mkstemp(p, "", i); /* now at the end of the page, no prefix */ |