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 <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/227
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
This commit is contained in:
Tobias Stoeckmann 2024-11-05 17:17:57 +01:00 committed by Lucas De Marchi
parent 6bd8c2bc7b
commit aad7c6973b

View File

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