* src/utils.c (make_directory): Replace alloca by fixed array / xmalloc

This commit is contained in:
Tim Rühsen 2020-02-13 12:09:34 +01:00
parent 4dd9dee2e7
commit 9adde1e441

View File

@ -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;
}