From 9adde1e4415f6091b96b8669b7613db78654e22f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20R=C3=BChsen?= Date: Thu, 13 Feb 2020 12:09:34 +0100 Subject: [PATCH] * src/utils.c (make_directory): Replace alloca by fixed array / xmalloc --- src/utils.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/utils.c b/src/utils.c index 75eada17..369100d6 100644 --- a/src/utils.c +++ b/src/utils.c @@ -956,11 +956,19 @@ int make_directory (const char *directory) { int i, ret, quit = 0; + char buf[1024]; char *dir; + size_t len = strlen (directory); /* Make a copy of dir, to be able to write to it. Otherwise, the function is unsafe if called with a read-only char *argument. */ - STRDUP_ALLOCA (dir, directory); + if (len < sizeof(buf)) + { + memcpy(buf, directory, len + 1); + dir = buf; + } + else + dir = xstrdup(directory); /* If the first character of dir is '/', skip it (and thus enable creation of absolute-pathname directories. */ @@ -983,6 +991,10 @@ make_directory (const char *directory) else dir[i] = '/'; } + + if (dir != buf) + xfree (dir); + return ret; }