Skip to content

Commit 078bf94

Browse files
Gax-cl0kod
authored andcommitted
samples/landlock: Fix possible NULL dereference in parse_path()
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]>
1 parent b665ee5 commit 078bf94

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

samples/landlock/sandboxer.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ static int parse_path(char *env_path, const char ***const path_list)
9191
}
9292
}
9393
*path_list = malloc(num_paths * sizeof(**path_list));
94+
if (!*path_list)
95+
return -1;
96+
9497
for (i = 0; i < num_paths; i++)
9598
(*path_list)[i] = strsep(&env_path, ENV_DELIMITER);
9699

@@ -127,6 +130,10 @@ static int populate_ruleset_fs(const char *const env_var, const int ruleset_fd,
127130
env_path_name = strdup(env_path_name);
128131
unsetenv(env_var);
129132
num_paths = parse_path(env_path_name, &path_list);
133+
if (num_paths < 0) {
134+
fprintf(stderr, "Failed to allocate memory\n");
135+
goto out_free_name;
136+
}
130137
if (num_paths == 1 && path_list[0][0] == '\0') {
131138
/*
132139
* Allows to not use all possible restrictions (e.g. use

0 commit comments

Comments
 (0)