Module Name: src
Committed By: christos
Date: Mon Jan 11 20:31:34 UTC 2021
Modified Files:
src/tests/lib/libc/stdlib: t_mktemp.c
Log Message:
Only try to create up-to NAME_MAX filenames.
XXX: this should be moved to stdio/t_mktemp.c where the rest of the tests
are and the code lives.
To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/lib/libc/stdlib/t_mktemp.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/tests/lib/libc/stdlib/t_mktemp.c
diff -u src/tests/lib/libc/stdlib/t_mktemp.c:1.3 src/tests/lib/libc/stdlib/t_mktemp.c:1.4
--- src/tests/lib/libc/stdlib/t_mktemp.c:1.3 Sun Nov 1 13:19:54 2020
+++ src/tests/lib/libc/stdlib/t_mktemp.c Mon Jan 11 15:31:34 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: t_mktemp.c,v 1.3 2020/11/01 18:19:54 gson Exp $ */
+/* $NetBSD: t_mktemp.c,v 1.4 2021/01/11 20:31:34 christos Exp $ */
/*-
* Copyright (c) 2013, 2020 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_mktemp.c,v 1.3 2020/11/01 18:19:54 gson Exp $");
+__RCSID("$NetBSD: t_mktemp.c,v 1.4 2021/01/11 20:31:34 christos Exp $");
#include <sys/stat.h>
@@ -79,10 +79,17 @@ ATF_TC_HEAD(mktemp_large_template, tc)
ATF_TC_BODY(mktemp_large_template, tc)
{
const char *path = "/tmp/mktemp.XXXXXX";
- char template[PATH_MAX] = { 0 };
+ char *template;
size_t i;
+ long name_max;
+ size_t tlen;
- atf_tc_expect_fail("PR lib/55441");
+ name_max = pathconf("/tmp/", _PC_NAME_MAX);
+ ATF_REQUIRE(name_max > 0);
+
+ tlen = (size_t)name_max + sizeof("/tmp/");
+ template = malloc(tlen);
+ ATF_REQUIRE(template != NULL);
ATF_REQUIRE(strcpy(template, path) != NULL);
ATF_REQUIRE(mktemp(template) != NULL);
@@ -90,16 +97,17 @@ ATF_TC_BODY(mktemp_large_template, tc)
ATF_REQUIRE(strcmp(template, path) != 0);
ATF_REQUIRE(strncmp(template, "/tmp/mktemp.", 12) == 0);
- (void)memset(template, '\0', sizeof(template));
+ (void)memset(template, '\0', tlen);
(void)strcpy(template, "/tmp/mktemp.");
- for (i = 12; i < sizeof(template) - 1; i++)
+ for (i = 12; i < tlen - 1; i++)
template[i] = 'X';
ATF_REQUIRE(mktemp(template) != NULL);
- ATF_REQUIRE(strlen(template) == sizeof(template) - 1);
+ ATF_REQUIRE(strlen(template) == tlen - 1);
ATF_REQUIRE(strcmp(template, path) != 0);
ATF_REQUIRE(strncmp(template, "/tmp/mktemp.", 12) == 0);
+ free(template);
}
ATF_TC(mkstemp_basic);