Skip to content

Commit

Permalink
core: Fix use after free case in load_from_path()
Browse files Browse the repository at this point in the history
ensure that mfree() on filename is called after the logging function
which uses the string pointed by filename

Signed-off-by: Khem Raj <raj.khem@gmail.com>
  • Loading branch information
kraj committed Dec 17, 2018
1 parent bfc4183 commit baa162c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/load-fragment.c
Expand Up @@ -4531,7 +4531,6 @@ static int load_from_path(Unit *u, const char *path) {
r = open_follow(&filename, &f, symlink_names, &id);
if (r >= 0)
break;
filename = mfree(filename);

/* ENOENT means that the file is missing or is a dangling symlink.
* ENOTDIR means that one of paths we expect to be is a directory
Expand All @@ -4543,6 +4542,7 @@ static int load_from_path(Unit *u, const char *path) {
else if (!IN_SET(r, -ENOENT, -ENOTDIR))
return r;

filename = mfree(filename);
/* Empty the symlink names for the next run */
set_clear_free(symlink_names);
}
Expand Down

0 comments on commit baa162c

Please sign in to comment.