From: Christian Marangi Date: Sun, 21 Jan 2024 23:39:50 +0000 (+0100) Subject: kmodloader: Fix NULL pointer dereferences error X-Git-Url: http://git.openwrt.org/?p=project%2Fubox.git;a=commitdiff_plain;h=b2f6da671f7c747fe9e65080c7c012b945cacb50 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 --- 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);