From 75b6cf9109045444be3a959b9090dcf695a2e662 Mon Sep 17 00:00:00 2001 From: guenther <> Date: Tue, 12 Mar 2013 15:01:19 +0000 Subject: Add check that mkstemp() fails with EINVAL if the string has fewer than 6 Xs --- src/regress/lib/libc/mkstemp/mkstemp_test.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'src') 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 @@ */ #include +#include +#include #include +#include #include #include #include -#include -#include #include #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 */ -- cgit v1.2.3-55-g6feb