[PATCH] samples/landlock: Fix possible NULL dereference in parse_path()
Gax-c
zichenxie0106 at gmail.com
Tue Nov 26 18:41:57 UTC 2024
From: Zichen Xie <zichenxie0106 at gmail.com>
malloc() may return NULL, leading to NULL dereference.
Add a NULL check.
Signed-off-by: Zichen Xie <zichenxie0106 at gmail.com>
---
samples/landlock/sandboxer.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/samples/landlock/sandboxer.c b/samples/landlock/sandboxer.c
index 57565dfd74a2..385fc115647f 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 == NULL)
+ return 1;
+
for (i = 0; i < num_paths; i++)
(*path_list)[i] = strsep(&env_path, ENV_DELIMITER);
--
2.34.1
More information about the Linux-security-module-archive
mailing list