Skip to content

Commit 9450b3c

Browse files
Gax-cgregkh
authored andcommitted
samples/landlock: Fix possible NULL dereference in parse_path()
[ Upstream commit 078bf94 ] malloc() may return NULL, leading to NULL dereference. Add a NULL check. Fixes: ba84b0b ("samples/landlock: Add a sandbox manager example") Signed-off-by: Zichen Xie <[email protected]> Link: https://lore.kernel.org/r/[email protected] [mic: Simplify fix] Signed-off-by: Mickaël Salaün <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent e30d21e commit 9450b3c

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

samples/landlock/sandboxer.c

+7
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ static int parse_path(char *env_path, const char ***const path_list)
6565
}
6666
}
6767
*path_list = malloc(num_paths * sizeof(**path_list));
68+
if (!*path_list)
69+
return -1;
70+
6871
for (i = 0; i < num_paths; i++)
6972
(*path_list)[i] = strsep(&env_path, ENV_PATH_TOKEN);
7073

@@ -100,6 +103,10 @@ static int populate_ruleset(const char *const env_var, const int ruleset_fd,
100103
env_path_name = strdup(env_path_name);
101104
unsetenv(env_var);
102105
num_paths = parse_path(env_path_name, &path_list);
106+
if (num_paths < 0) {
107+
fprintf(stderr, "Failed to allocate memory\n");
108+
goto out_free_name;
109+
}
103110
if (num_paths == 1 && path_list[0][0] == '\0') {
104111
/*
105112
* Allows to not use all possible restrictions (e.g. use

0 commit comments

Comments
 (0)