[git commit] mkdtemp: proper error detection on mktemp

Denys Vlasenko vda.linux at googlemail.com
Tue Dec 8 17:46:32 UTC 2020


commit: https://git.busybox.net/busybox/commit/?id=abaee4aada7c91da6a43a83e9a73f98916a803a4
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master

On error, mktemp returns an empty string, not NULL.

Signed-off-by: Xabier Oneca <xoneca at gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 libbb/platform.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libbb/platform.c b/libbb/platform.c
index 03bbb798b..d2b263a6d 100644
--- a/libbb/platform.c
+++ b/libbb/platform.c
@@ -107,7 +107,8 @@ void* FAST_FUNC memrchr(const void *s, int c, size_t n)
 /* This is now actually part of POSIX.1, but was only added in 2008 */
 char* FAST_FUNC mkdtemp(char *template)
 {
-	if (mktemp(template) == NULL || mkdir(template, 0700) != 0)
+	/* NB: on error, mktemp returns an empty string, not NULL */
+	if (mktemp(template)[0] == '\0' || mkdir(template, 0700) != 0)
 		return NULL;
 	return template;
 }


More information about the busybox-cvs mailing list