132 lines
4.9 KiB
Diff
132 lines
4.9 KiB
Diff
|
From bbfdf6a435cbd5f71ae76f962ce86786346589aa Mon Sep 17 00:00:00 2001
|
||
|
From: =?UTF-8?q?Petr=20Men=C5=A1=C3=ADk?= <pemensik@redhat.com>
|
||
|
Date: Fri, 3 Sep 2021 17:19:05 +0200
|
||
|
Subject: [PATCH 08/15] Fix coverity warnings on dbus
|
||
|
|
||
|
Error: CLANG_WARNING: [#def30]
|
||
|
dnsmasq-2.86test7/src/dbus.c:117:3: warning[deadcode.DeadStores]: Value stored to 'w' is never read
|
||
|
# 115| daemon->watches = w;
|
||
|
# 116|
|
||
|
# 117|-> w = data; /* no warning */
|
||
|
# 118| return TRUE;
|
||
|
# 119| }
|
||
|
|
||
|
Error: CLANG_WARNING: [#def31]
|
||
|
dnsmasq-2.86test7/src/dbus.c:137:3: warning[deadcode.DeadStores]: Value stored to 'w' is never read
|
||
|
# 135| }
|
||
|
# 136|
|
||
|
# 137|-> w = data; /* no warning */
|
||
|
# 138| }
|
||
|
# 139|
|
||
|
|
||
|
Error: CHECKED_RETURN (CWE-252): [#def32]
|
||
|
dnsmasq-2.86test7/src/dbus.c:146: check_return: Calling "dbus_message_iter_init" without checking return value (as is done elsewhere 4 out of 5 times).
|
||
|
dnsmasq-2.86test7/src/dbus.c:460: example_checked: Example 1: "dbus_message_iter_init(message, &iter)" has its value checked in "dbus_message_iter_init(message, &iter)".
|
||
|
dnsmasq-2.86test7/src/dbus.c:573: example_checked: Example 2: "dbus_message_iter_init(message, &iter)" has its value checked in "dbus_message_iter_init(message, &iter)".
|
||
|
dnsmasq-2.86test7/src/dbus.c:257: example_checked: Example 3: "dbus_message_iter_init(message, &iter)" has its value checked in "dbus_message_iter_init(message, &iter)".
|
||
|
dnsmasq-2.86test7/src/dbus.c:427: example_checked: Example 4: "dbus_message_iter_init(message, &iter)" has its value checked in "dbus_message_iter_init(message, &iter)".
|
||
|
# 144| char *domain;
|
||
|
# 145|
|
||
|
# 146|-> dbus_message_iter_init(message, &iter);
|
||
|
# 147|
|
||
|
# 148| mark_servers(SERV_FROM_DBUS);
|
||
|
|
||
|
Error: NEGATIVE_RETURNS (CWE-394): [#def33]
|
||
|
dnsmasq-2.86test7/src/dbus.c:547: negative_return_fn: Function "parse_hex((char *)hwaddr, dhcp_chaddr, 16, NULL, &hw_type)" returns a negative number.
|
||
|
dnsmasq-2.86test7/src/dbus.c:547: assign: Assigning: "hw_len" = "parse_hex((char *)hwaddr, dhcp_chaddr, 16, NULL, &hw_type)".
|
||
|
dnsmasq-2.86test7/src/dbus.c:551: negative_returns: "hw_len" is passed to a parameter that cannot be negative.
|
||
|
# 549| hw_type = ARPHRD_ETHER;
|
||
|
# 550|
|
||
|
# 551|-> lease_set_hwaddr(lease, dhcp_chaddr, clid, hw_len, hw_type,
|
||
|
# 552| clid_len, now, 0);
|
||
|
# 553| lease_set_expires(lease, expires, now);
|
||
|
|
||
|
Error: CLANG_WARNING: [#def34]
|
||
|
dnsmasq-2.86test7/src/dbus.c:722:3: warning[deadcode.DeadStores]: Value stored to 'method' is never read
|
||
|
# 720| clear_cache_and_reload(dnsmasq_time());
|
||
|
# 721|
|
||
|
# 722|-> method = user_data; /* no warning */
|
||
|
# 723|
|
||
|
# 724| /* If no reply or no error, return nothing */
|
||
|
---
|
||
|
src/dbus.c | 21 +++++++++++++++------
|
||
|
1 file changed, 15 insertions(+), 6 deletions(-)
|
||
|
|
||
|
diff --git a/src/dbus.c b/src/dbus.c
|
||
|
index cbdce9c..d746b9a 100644
|
||
|
--- a/src/dbus.c
|
||
|
+++ b/src/dbus.c
|
||
|
@@ -114,7 +114,7 @@ static dbus_bool_t add_watch(DBusWatch *watch, void *data)
|
||
|
w->next = daemon->watches;
|
||
|
daemon->watches = w;
|
||
|
|
||
|
- w = data; /* no warning */
|
||
|
+ (void)data; /* no warning */
|
||
|
return TRUE;
|
||
|
}
|
||
|
|
||
|
@@ -134,16 +134,20 @@ static void remove_watch(DBusWatch *watch, void *data)
|
||
|
up = &(w->next);
|
||
|
}
|
||
|
|
||
|
- w = data; /* no warning */
|
||
|
+ (void)data; /* no warning */
|
||
|
}
|
||
|
|
||
|
-static void dbus_read_servers(DBusMessage *message)
|
||
|
+static DBusMessage* dbus_read_servers(DBusMessage *message)
|
||
|
{
|
||
|
DBusMessageIter iter;
|
||
|
union mysockaddr addr, source_addr;
|
||
|
char *domain;
|
||
|
|
||
|
- dbus_message_iter_init(message, &iter);
|
||
|
+ if (!dbus_message_iter_init(message, &iter))
|
||
|
+ {
|
||
|
+ return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
|
||
|
+ "Failed to initialize dbus message iter");
|
||
|
+ }
|
||
|
|
||
|
mark_servers(SERV_FROM_DBUS);
|
||
|
|
||
|
@@ -222,6 +226,7 @@ static void dbus_read_servers(DBusMessage *message)
|
||
|
|
||
|
/* unlink and free anything still marked. */
|
||
|
cleanup_servers();
|
||
|
+ return NULL;
|
||
|
}
|
||
|
|
||
|
#ifdef HAVE_LOOP
|
||
|
@@ -545,6 +550,10 @@ static DBusMessage *dbus_add_lease(DBusMessage* message)
|
||
|
"Invalid IP address '%s'", ipaddr);
|
||
|
|
||
|
hw_len = parse_hex((char*)hwaddr, dhcp_chaddr, DHCP_CHADDR_MAX, NULL, &hw_type);
|
||
|
+ if (hw_len < 0)
|
||
|
+ return dbus_message_new_error_printf(message, DBUS_ERROR_INVALID_ARGS,
|
||
|
+ "Invalid HW address '%s'", hwaddr);
|
||
|
+
|
||
|
if (hw_type == 0 && hw_len != 0)
|
||
|
hw_type = ARPHRD_ETHER;
|
||
|
|
||
|
@@ -668,7 +677,7 @@ DBusHandlerResult message_handler(DBusConnection *connection,
|
||
|
#endif
|
||
|
else if (strcmp(method, "SetServers") == 0)
|
||
|
{
|
||
|
- dbus_read_servers(message);
|
||
|
+ reply = dbus_read_servers(message);
|
||
|
new_servers = 1;
|
||
|
}
|
||
|
else if (strcmp(method, "SetServersEx") == 0)
|
||
|
@@ -719,7 +728,7 @@ DBusHandlerResult message_handler(DBusConnection *connection,
|
||
|
if (clear_cache)
|
||
|
clear_cache_and_reload(dnsmasq_time());
|
||
|
|
||
|
- method = user_data; /* no warning */
|
||
|
+ (void)user_data; /* no warning */
|
||
|
|
||
|
/* If no reply or no error, return nothing */
|
||
|
if (!reply)
|
||
|
--
|
||
|
2.31.1
|
||
|
|