]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
libkmod: Prevent ouf of boundary access
authorTobias Stoeckmann <tobias@stoeckmann.org>
Tue, 5 Nov 2024 16:17:57 +0000 (17:17 +0100)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Thu, 7 Nov 2024 20:29:52 +0000 (14:29 -0600)
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>
libkmod/libkmod-module.c

index 905b050da84c9252537c3e3403a79f02a287ec6b..47c6305a529ede20d1f73c94d273cfc4b8e3baa2 100644 (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);
        }