Commit 4990f04a authored by Max Kellermann's avatar Max Kellermann

update: make addDirectoryPathToDB() non-recursive

This recursive function is very dangerous because it allocates a large buffer on the stack in every iteration. That may be misused to generate a stack overflow.
parent 8536a979
...@@ -354,21 +354,25 @@ directory_make_child_checked(struct directory *parent, const char *path) ...@@ -354,21 +354,25 @@ directory_make_child_checked(struct directory *parent, const char *path)
static struct directory * static struct directory *
addDirectoryPathToDB(const char *utf8path) addDirectoryPathToDB(const char *utf8path)
{ {
char path_max_tmp[MPD_PATH_MAX]; struct directory *directory = db_get_root();
char *parent; char *duplicated = xstrdup(utf8path);
struct directory *parentDirectory; char *slash = duplicated;
parent = parent_path(path_max_tmp, utf8path); while (true) {
slash = strchr(slash, '/');
if (slash != NULL)
*slash = 0;
if (strlen(parent) == 0) directory = directory_make_child_checked(directory,
parentDirectory = db_get_root(); duplicated);
else if (directory == NULL || slash == NULL)
parentDirectory = addDirectoryPathToDB(parent); break;
if (!parentDirectory) *slash++ = '/';
return NULL; }
return directory_make_child_checked(parentDirectory, utf8path); free(duplicated);
return directory;
} }
static struct directory * static struct directory *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment