summaryrefslogtreecommitdiff
path: root/samples
diff options
context:
space:
mode:
authorZichen Xie <zichenxie0106@gmail.com>2024-11-27 21:29:56 -0600
committerMickaël Salaün <mic@digikod.net>2025-01-10 12:12:40 +0100
commit078bf9438a31567e2c0587159ccefde835fb1ced (patch)
tree112484286b4a4339f5f435ab1c24d72e3feb4c38 /samples
parentb665ee5f08df401a9e4a68e7d5f662d3f72ba1e1 (diff)
samples/landlock: Fix possible NULL dereference in parse_path()
malloc() may return NULL, leading to NULL dereference. Add a NULL check. Fixes: ba84b0bf5a16 ("samples/landlock: Add a sandbox manager example") Signed-off-by: Zichen Xie <zichenxie0106@gmail.com> Link: https://lore.kernel.org/r/20241128032955.11711-1-zichenxie0106@gmail.com [mic: Simplify fix] Signed-off-by: Mickaël Salaün <mic@digikod.net>
Diffstat (limited to 'samples')
-rw-r--r--samples/landlock/sandboxer.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/samples/landlock/sandboxer.c b/samples/landlock/sandboxer.c
index 57565dfd74a2..07fab2ef534e 100644
--- a/samples/landlock/sandboxer.c
+++ b/samples/landlock/sandboxer.c
@@ -91,6 +91,9 @@ static int parse_path(char *env_path, const char ***const path_list)
}
}
*path_list = malloc(num_paths * sizeof(**path_list));
+ if (!*path_list)
+ return -1;
+
for (i = 0; i < num_paths; i++)
(*path_list)[i] = strsep(&env_path, ENV_DELIMITER);
@@ -127,6 +130,10 @@ static int populate_ruleset_fs(const char *const env_var, const int ruleset_fd,
env_path_name = strdup(env_path_name);
unsetenv(env_var);
num_paths = parse_path(env_path_name, &path_list);
+ if (num_paths < 0) {
+ fprintf(stderr, "Failed to allocate memory\n");
+ goto out_free_name;
+ }
if (num_paths == 1 && path_list[0][0] == '\0') {
/*
* Allows to not use all possible restrictions (e.g. use