diff options
author | guenther <> | 2013-03-12 15:01:19 +0000 |
---|---|---|
committer | guenther <> | 2013-03-12 15:01:19 +0000 |
commit | 75b6cf9109045444be3a959b9090dcf695a2e662 (patch) | |
tree | 16a66e11d80537c944d2c09a095aa009a8cf4c0b /src | |
parent | de2b8717a5086120258307493b380d416f13fc11 (diff) | |
download | openbsd-75b6cf9109045444be3a959b9090dcf695a2e662.tar.gz openbsd-75b6cf9109045444be3a959b9090dcf695a2e662.tar.bz2 openbsd-75b6cf9109045444be3a959b9090dcf695a2e662.zip |
Add check that mkstemp() fails with EINVAL if the string has fewer than
6 Xs
Diffstat (limited to 'src')
-rw-r--r-- | src/regress/lib/libc/mkstemp/mkstemp_test.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/regress/lib/libc/mkstemp/mkstemp_test.c b/src/regress/lib/libc/mkstemp/mkstemp_test.c index fd133d8368..ef973b061b 100644 --- a/src/regress/lib/libc/mkstemp/mkstemp_test.c +++ b/src/regress/lib/libc/mkstemp/mkstemp_test.c | |||
@@ -9,17 +9,19 @@ | |||
9 | */ | 9 | */ |
10 | 10 | ||
11 | #include <sys/param.h> | 11 | #include <sys/param.h> |
12 | #include <sys/mman.h> | ||
13 | #include <sys/stat.h> | ||
12 | 14 | ||
13 | #include <err.h> | 15 | #include <err.h> |
16 | #include <errno.h> | ||
14 | #include <stdio.h> | 17 | #include <stdio.h> |
15 | #include <stdlib.h> | 18 | #include <stdlib.h> |
16 | #include <string.h> | 19 | #include <string.h> |
17 | #include <sys/mman.h> | ||
18 | #include <sys/stat.h> | ||
19 | #include <unistd.h> | 20 | #include <unistd.h> |
20 | 21 | ||
21 | #define MAX_TEMPLATE_LEN 10 | 22 | #define MAX_TEMPLATE_LEN 10 |
22 | #define MAX_TRIES 100 | 23 | #define MAX_TRIES 100 |
24 | #define MIN_Xs 6 | ||
23 | 25 | ||
24 | #define SUFFIX ".suff" | 26 | #define SUFFIX ".suff" |
25 | #define SLEN (sizeof SUFFIX - 1) | 27 | #define SLEN (sizeof SUFFIX - 1) |
@@ -38,8 +40,15 @@ check(int fd, char const *path, char const *prefix, size_t plen, | |||
38 | struct stat sb, fsb; | 40 | struct stat sb, fsb; |
39 | char const *p; | 41 | char const *p; |
40 | 42 | ||
43 | if (tlen < MIN_Xs) { | ||
44 | if (fd >= 0) | ||
45 | errx(1, "mkstemp(%s) succeed with too few Xs", path); | ||
46 | if (errno != EINVAL) | ||
47 | err(1, "mkstemp(%s) failed with wrong errno", path); | ||
48 | return 1; | ||
49 | } | ||
41 | if (fd < 0) | 50 | if (fd < 0) |
42 | err(1, "mkstemp"); | 51 | err(1, "mkstemp(%s)", path); |
43 | if (stat(path, &sb)) | 52 | if (stat(path, &sb)) |
44 | err(1, "stat(%s)", path); | 53 | err(1, "stat(%s)", path); |
45 | if (fstat(fd, &fsb)) | 54 | if (fstat(fd, &fsb)) |
@@ -120,7 +129,7 @@ main(void) | |||
120 | p += pg; | 129 | p += pg; |
121 | 130 | ||
122 | i = MAX_TEMPLATE_LEN + 1; | 131 | i = MAX_TEMPLATE_LEN + 1; |
123 | while (i-- > 1) { | 132 | while (i-- > 0) { |
124 | /* try first at the start of a page, no prefix */ | 133 | /* try first at the start of a page, no prefix */ |
125 | try_mkstemp(p, "", i); | 134 | try_mkstemp(p, "", i); |
126 | /* now at the end of the page, no prefix */ | 135 | /* now at the end of the page, no prefix */ |