diff mbox series

samples/landlock: Fix possible NULL dereference in parse_path()

Message ID 20241126184156.12503-1-zichenxie0106@gmail.com (mailing list archive)
State New
Headers show
Series samples/landlock: Fix possible NULL dereference in parse_path() | expand

Commit Message

Gax-c Nov. 26, 2024, 6:41 p.m. UTC
From: Zichen Xie <zichenxie0106@gmail.com>

malloc() may return NULL, leading to NULL dereference.
Add a NULL check.

Signed-off-by: Zichen Xie <zichenxie0106@gmail.com>
---
 samples/landlock/sandboxer.c | 3 +++
 1 file changed, 3 insertions(+)
diff mbox series

Patch

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);