From 98c6168d648f763d979cba81502f43e5725f50b6 Mon Sep 17 00:00:00 2001 From: Tobias Stoeckmann Date: Tue, 5 Nov 2024 17:17:57 +0100 Subject: [PATCH] libkmod: Prevent ouf of boundary access Do not access memory out of bounds if the first character read by fgets is NUL. Treat such a character as EOL instead. This is a purely defensive measure since /proc/modules should normaly not contain such characters. Signed-off-by: Tobias Stoeckmann --- libkmod/libkmod-module.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c index 905b050d..47c6305a 100644 --- a/libkmod/libkmod-module.c +++ b/libkmod/libkmod-module.c @@ -1382,7 +1382,7 @@ KMOD_EXPORT int kmod_module_new_from_loaded(struct kmod_ctx *ctx, struct kmod_li kmod_module_unref(m); } eat_line: - while (line[len - 1] != '\n' && fgets(line, sizeof(line), fp)) + while (len > 0 && line[len - 1] != '\n' && fgets(line, sizeof(line), fp)) len = strlen(line); }