|
|
From 2c944edcd933de0860459a7011581c8a40a3c56f Mon Sep 17 00:00:00 2001
|
|
|
From: Coiby Xu <coiby.xu@gmail.com>
|
|
|
Date: Tue, 15 Jun 2021 11:03:21 +0800
|
|
|
Subject: [PATCH 7/8] fix Error: FORWARD_NULL (CWE-476): [#def23]
|
|
|
|
|
|
Fix the following errors found by covscan,
|
|
|
|
|
|
Error: FORWARD_NULL (CWE-476): [#def23]
|
|
|
python-dmidecode-3.12.2/src/dmilog.c:48: var_compare_op: Comparing "ret" to null implies that "ret" might be null.
|
|
|
python-dmidecode-3.12.2/src/dmilog.c:51: var_deref_op: Dereferencing null pointer "ret".
|
|
|
# 49| fprintf(stderr, "** ERROR ** Could not allocate memory for log data\n");
|
|
|
# 50| }
|
|
|
# 51|-> ret->level = -1; // Initialised - chain header pointer always have -1.
|
|
|
# 52| return ret;
|
|
|
# 53| }
|
|
|
|
|
|
Error: CLANG_WARNING: [#def24]
|
|
|
python-dmidecode-3.12.2/src/dmilog.c:51:13: warning[core.NullDereference]: Access to field 'level' results in a dereference of a null pointer (loaded from variable 'ret')
|
|
|
# 49| fprintf(stderr, "** ERROR ** Could not allocate memory for log data\n");
|
|
|
# 50| }
|
|
|
# 51|-> ret->level = -1; // Initialised - chain header pointer always have -1.
|
|
|
# 52| return ret;
|
|
|
# 53| }
|
|
|
|
|
|
Error: GCC_ANALYZER_WARNING (CWE-476): [#def25]
|
|
|
python-dmidecode-3.12.2/src/dmilog.c: scope_hint: In function 'log_init'
|
|
|
python-dmidecode-3.12.2/src/dmilog.c:51:20: warning[-Wanalyzer-null-dereference]: dereference of NULL 'ret'
|
|
|
# 49| fprintf(stderr, "** ERROR ** Could not allocate memory for log data\n");
|
|
|
# 50| }
|
|
|
# 51|-> ret->level = -1; // Initialised - chain header pointer always have -1.
|
|
|
# 52| return ret;
|
|
|
# 53| }
|
|
|
|
|
|
Error: GCC_ANALYZER_WARNING (CWE-476): [#def26]
|
|
|
python-dmidecode-3.12.2/src/dmilog.c: scope_hint: In function log_init
|
|
|
python-dmidecode-3.12.2/src/dmilog.c:51:20: warning[-Wanalyzer-null-dereference]: dereference of NULL ret
|
|
|
# 49| fprintf(stderr, "** ERROR ** Could not allocate memory for log data\n");
|
|
|
# 50| }
|
|
|
# 51|-> ret->level = -1; // Initialised - chain header pointer always have -1.
|
|
|
# 52| return ret;
|
|
|
# 53| }
|
|
|
|
|
|
Signed-off-by: Coiby Xu <coiby.xu@gmail.com>
|
|
|
---
|
|
|
src/dmilog.c | 1 +
|
|
|
1 file changed, 1 insertion(+)
|
|
|
|
|
|
diff --git a/src/dmilog.c b/src/dmilog.c
|
|
|
index f7ade5d..80b2ac3 100644
|
|
|
--- a/src/dmilog.c
|
|
|
+++ b/src/dmilog.c
|
|
|
@@ -47,6 +47,7 @@ Log_t * log_init()
|
|
|
ret = (Log_t *) calloc(1, sizeof(Log_t)+2);
|
|
|
if( !ret ) {
|
|
|
fprintf(stderr, "** ERROR ** Could not allocate memory for log data\n");
|
|
|
+ return ret;
|
|
|
}
|
|
|
ret->level = -1; // Initialised - chain header pointer always have -1.
|
|
|
return ret;
|
|
|
--
|
|
|
2.31.1
|
|
|
|