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