From b2f6da671f7c747fe9e65080c7c012b945cacb50 Mon Sep 17 00:00:00 2001 From: Christian Marangi Date: Mon, 22 Jan 2024 00:39:50 +0100 Subject: [PATCH] kmodloader: Fix NULL pointer dereferences error Fix NULL pointer dereferences reported by Coverity Scan. Return early instead of jumping to out and trying to fclose a NULL pointer. Fix - CID 1586642: Null pointer dereferences (FORWARD_NULL) - CID 1586641: Null pointer dereferences (FORWARD_NULL) Signed-off-by: Christian Marangi --- kmodloader.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/kmodloader.c b/kmodloader.c index b4ef52a..2cb6088 100644 --- a/kmodloader.c +++ b/kmodloader.c @@ -328,7 +328,7 @@ static int scan_loaded_modules(void) fp = fopen("/proc/modules", "r"); if (!fp) { ULOG_ERR("failed to open /proc/modules\n"); - goto out; + return -1; } while (getline(&buf, &buf_len, fp) > 0) { @@ -499,7 +499,7 @@ static int scan_builtin_modules(void) int rv = -1; if (!module_folders && init_module_folders()) - goto err; + return -1; for (p = module_folders; *p; p++) { snprintf(path, sizeof(path), "%s%s", *p, MOD_BUILTIN); if (!stat(path, &st) && S_ISREG(st.st_mode)) { @@ -509,7 +509,7 @@ static int scan_builtin_modules(void) } } if (!fp) - goto out; /* OK if modules.builtin unavailable */ + return 0; /* OK if modules.builtin unavailable */ while (getline(&buf, &buf_len, fp) > 0) { struct module *m; @@ -529,7 +529,7 @@ static int scan_builtin_modules(void) goto err; } } -out: + rv = 0; err: free(buf); -- 2.30.2