diff mbox series

[BlueZ,04/15] tools/mesh-cfgclient: Fix uninitialised variable usage

Message ID 20240516090340.61417-5-hadess@hadess.net (mailing list archive)
State Accepted
Commit c63b7b0d732ef73c7a9d3cdcbbd20fe4ccdd6a87
Headers show
Series Fix a number of static analysis issues #2 | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success
tedd_an/CheckPatch success CheckPatch PASS
tedd_an/GitLint fail WARNING: I3 - ignore-body-lines: gitlint will be switching from using Python regex 'match' (match beginning) to 'search' (match anywhere) semantics. Please review your ignore-body-lines.regex option accordingly. To remove this warning, set general.regex-style-search=True. More details: https://jorisroovers.github.io/gitlint/configuration/#regex-style-search 4: B1 Line exceeds max length (100>80): "bluez-5.75/tools/mesh-cfgclient.c:1992:2: var_decl: Declaring variable "result" without initializer." 5: B1 Line exceeds max length (132>80): "bluez-5.75/tools/mesh-cfgclient.c:2041:3: uninit_use: Using uninitialized value "result". Field "result.last_seen" is uninitialized." 6: B3 Line contains hard tab characters (\t): "2039| l_queue_length(devices) + 1);" 7: B3 Line contains hard tab characters (\t): "2040| dev = l_malloc(sizeof(struct unprov_device));" 8: B3 Line contains hard tab characters (\t): "2041|-> *dev = result;" 10: B3 Line contains hard tab characters (\t): "2043| } else if (dev->rssi < result.rssi)" 13: B1 Line exceeds max length (100>80): "bluez-5.75/tools/mesh-cfgclient.c:1992:2: var_decl: Declaring variable "result" without initializer." 14: B1 Line exceeds max length (132>80): "bluez-5.75/tools/mesh-cfgclient.c:2044:3: uninit_use: Using uninitialized value "result". Field "result.last_seen" is uninitialized." 16: B3 Line contains hard tab characters (\t): "2043| } else if (dev->rssi < result.rssi)" 17: B3 Line contains hard tab characters (\t): "2044|-> *dev = result;" 19: B3 Line contains hard tab characters (\t): "2046| dev->last_seen = time(NULL);"
tedd_an/IncrementalBuild success Incremental Build PASS

Commit Message

Bastien Nocera May 16, 2024, 9:03 a.m. UTC
Error: UNINIT (CWE-457): [#def64] [important]
bluez-5.75/tools/mesh-cfgclient.c:1992:2: var_decl: Declaring variable "result" without initializer.
bluez-5.75/tools/mesh-cfgclient.c:2041:3: uninit_use: Using uninitialized value "result". Field "result.last_seen" is uninitialized.
2039|							l_queue_length(devices) + 1);
2040|			dev = l_malloc(sizeof(struct unprov_device));
2041|->			*dev = result;
2042|
2043|		} else if (dev->rssi < result.rssi)

Error: UNINIT (CWE-457): [#def65] [important]
bluez-5.75/tools/mesh-cfgclient.c:1992:2: var_decl: Declaring variable "result" without initializer.
bluez-5.75/tools/mesh-cfgclient.c:2044:3: uninit_use: Using uninitialized value "result". Field "result.last_seen" is uninitialized.
2042|
2043|		} else if (dev->rssi < result.rssi)
2044|->			*dev = result;
2045|
2046|		dev->last_seen = time(NULL);
---
 tools/mesh-cfgclient.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/tools/mesh-cfgclient.c b/tools/mesh-cfgclient.c
index 6d2d34409fe3..e39f145c6241 100644
--- a/tools/mesh-cfgclient.c
+++ b/tools/mesh-cfgclient.c
@@ -2021,6 +2021,7 @@  static struct l_dbus_message *scan_result_call(struct l_dbus *dbus,
 	result.server = server;
 	result.rssi = rssi;
 	result.id = 0;
+	result.last_seen = time(NULL);
 
 	if (n > 16 && n <= 18)
 		result.oob_info = l_get_be16(prov_data + 16);
@@ -2043,8 +2044,6 @@  static struct l_dbus_message *scan_result_call(struct l_dbus *dbus,
 	} else if (dev->rssi < result.rssi)
 		*dev = result;
 
-	dev->last_seen = time(NULL);
-
 	l_queue_insert(devices, dev, sort_rssi, NULL);
 
 done: