From d637b3efae3cf682aa431248ef4dde3bc52204be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Klime=C5=A1?= Date: Thu, 4 Dec 2014 17:00:01 +0100 Subject: libnm: missing break on get_property Coverity: Defect type: MISSING_BREAK libnm/nm-dhcp-config.c:117: fallthrough: The above case falls through to this one. --- libnm/nm-dhcp-config.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libnm/nm-dhcp-config.c b/libnm/nm-dhcp-config.c index 86cbdc3e3c..4a58bf27a6 100644 --- a/libnm/nm-dhcp-config.c +++ b/libnm/nm-dhcp-config.c @@ -114,6 +114,7 @@ get_property (GObject *object, switch (prop_id) { case PROP_FAMILY: g_value_set_int (value, nm_dhcp_config_get_family (self)); + break; case PROP_OPTIONS: g_value_set_boxed (value, nm_dhcp_config_get_options (self)); break; -- cgit v1.2.1 From e52f352339f272987c415ba1512f3b9fbcb92509 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Klime=C5=A1?= Date: Thu, 4 Dec 2014 18:11:39 +0100 Subject: util: fix _log_connection_sort_names_fcn() Coverity: Defect type: CONSTANT_EXPRESSION_RESULT src/NetworkManagerUtils.c:1978: same_on_both_sides: "(v1->diff_result & NM_SETTING_DIFF_RESULT_IN_B) != (v1->diff_result & NM_SETTING_DIFF_RESULT_IN_B)" is always false regardless of the values of its operands because those operands are identical. This occurs as the logical operand of if. --- src/NetworkManagerUtils.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/NetworkManagerUtils.c b/src/NetworkManagerUtils.c index 6ca2d9920d..03a3ec2e8f 100644 --- a/src/NetworkManagerUtils.c +++ b/src/NetworkManagerUtils.c @@ -2015,9 +2015,9 @@ _log_connection_sort_names_fcn (gconstpointer a, gconstpointer b) /* we want to first show the items, that disappeared, then the one that changed and * then the ones that were added. */ - if ((v1->diff_result & NM_SETTING_DIFF_RESULT_IN_A) != (v1->diff_result & NM_SETTING_DIFF_RESULT_IN_A)) + if ((v1->diff_result & NM_SETTING_DIFF_RESULT_IN_A) != (v2->diff_result & NM_SETTING_DIFF_RESULT_IN_A)) return (v1->diff_result & NM_SETTING_DIFF_RESULT_IN_A) ? -1 : 1; - if ((v1->diff_result & NM_SETTING_DIFF_RESULT_IN_B) != (v1->diff_result & NM_SETTING_DIFF_RESULT_IN_B)) + if ((v1->diff_result & NM_SETTING_DIFF_RESULT_IN_B) != (v2->diff_result & NM_SETTING_DIFF_RESULT_IN_B)) return (v1->diff_result & NM_SETTING_DIFF_RESULT_IN_B) ? 1 : -1; return strcmp (v1->item_name, v2->item_name); } -- cgit v1.2.1 From 0da3b96ab5ef1dad9b6c729c1019aeb27d487f0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Klime=C5=A1?= Date: Thu, 4 Dec 2014 17:45:05 +0100 Subject: libnm-core: do not access array if it is NULL Coverity: Defect type: FORWARD_NULL libnm-core/nm-setting-8021x.c:1684: var_deref_op: Dereferencing null pointer "array". --- libnm-core/nm-setting-8021x.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libnm-core/nm-setting-8021x.c b/libnm-core/nm-setting-8021x.c index 369359f47a..f739f2c720 100644 --- a/libnm-core/nm-setting-8021x.c +++ b/libnm-core/nm-setting-8021x.c @@ -1680,8 +1680,9 @@ file_to_secure_bytes (const char *filename) g_byte_array_append (array, (guint8 *) contents, length); g_assert (array->len == length); g_free (contents); + return g_bytes_new_with_free_func (array->data, array->len, free_secure_bytes, array); } - return g_bytes_new_with_free_func (array->data, array->len, free_secure_bytes, array); + return NULL; } /** -- cgit v1.2.1 From f93128194eb6e0d3ba7387ff6fc4430da6ae6cfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Klime=C5=A1?= Date: Thu, 4 Dec 2014 17:50:03 +0100 Subject: tui: set GError so that it is not NULL later Coverity: Defect type: FORWARD_NULL clients/tui/nmtui-edit.c:467: var_deref_op: Dereferencing null pointer "error". --- clients/tui/nmtui-edit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clients/tui/nmtui-edit.c b/clients/tui/nmtui-edit.c index 2cc6b773aa..94d15fb3b2 100644 --- a/clients/tui/nmtui-edit.c +++ b/clients/tui/nmtui-edit.c @@ -463,7 +463,7 @@ connection_deleted_callback (GObject *connection, ConnectionDeleteData *data = user_data; GError *error = NULL; - if (!nm_remote_connection_delete_finish (data->connection, result, NULL)) { + if (!nm_remote_connection_delete_finish (data->connection, result, &error)) { nmt_newt_message_dialog (_("Unable to delete connection: %s"), error->message); } else -- cgit v1.2.1 From d80bb52872e0c8b520c92e9839843fda83a41a95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Klime=C5=A1?= Date: Thu, 4 Dec 2014 16:39:45 +0100 Subject: tui: width and height parameters was swapped, but they are ignored anyway Coverity: Defect type: SWAPPED_ARGUMENTS clients/tui/newt/nmt-newt-section.c:328: swapped_arguments: The positions of arguments in the call to "nmt_newt_widget_size_request" do not match the ordering of the parameters: * "&border_height" is passed to "width" * "&border_width" is passed to "height" --- clients/tui/newt/nmt-newt-section.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/clients/tui/newt/nmt-newt-section.c b/clients/tui/newt/nmt-newt-section.c index df5b188945..1a5035fc09 100644 --- a/clients/tui/newt/nmt-newt-section.c +++ b/clients/tui/newt/nmt-newt-section.c @@ -260,12 +260,12 @@ nmt_newt_section_size_request (NmtNewtWidget *widget, int *height) { NmtNewtSectionPrivate *priv = NMT_NEWT_SECTION_GET_PRIVATE (widget); - int border_width, border_height; + int w_ignore, h_ignore; g_return_if_fail (priv->header != NULL && priv->body != NULL); if (priv->show_border) - nmt_newt_widget_size_request (priv->border_grid, &border_width, &border_height); + nmt_newt_widget_size_request (priv->border_grid, &w_ignore, &h_ignore); nmt_newt_widget_size_request (priv->header, &priv->hwidth_req, &priv->hheight_req); nmt_newt_widget_size_request (priv->body, &priv->bwidth_req, &priv->bheight_req); @@ -322,10 +322,10 @@ nmt_newt_section_size_allocate (NmtNewtWidget *widget, NmtNewtSectionPrivate *priv = NMT_NEWT_SECTION_GET_PRIVATE (widget); if (priv->show_border) { - int border_height, border_width; + int w_ignore, h_ignore; adjust_border_for_allocation (priv, height); - nmt_newt_widget_size_request (priv->border_grid, &border_height, &border_width); + nmt_newt_widget_size_request (priv->border_grid, &w_ignore, &h_ignore); nmt_newt_widget_size_allocate (priv->border_grid, x, y, 1, height); nmt_newt_widget_size_allocate (priv->header, x + 2, y, width, priv->hheight_req); } else -- cgit v1.2.1 From 7744bd0f8541307d4b0e6a4e919f29564543cbc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Klime=C5=A1?= Date: Thu, 4 Dec 2014 16:57:06 +0100 Subject: utils: initialize timespec structure Coverity: Defect type: UNINIT src/NetworkManagerUtils.c:1906: uninit_use_in_call: Using uninitialized value "tp.tv_nsec" when calling "monotonic_timestamp_get". src/NetworkManagerUtils.c:1879: uninit_use_in_call: Using uninitialized value "tp.tv_nsec" when calling "monotonic_timestamp_get". src/NetworkManagerUtils.c:1852: uninit_use_in_call: Using uninitialized value "tp.tv_nsec" when calling "monotonic_timestamp_get". src/NetworkManagerUtils.c:1825: uninit_use_in_call: Using uninitialized value "tp.tv_nsec" when calling "monotonic_timestamp_get". --- src/NetworkManagerUtils.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/NetworkManagerUtils.c b/src/NetworkManagerUtils.c index 03a3ec2e8f..ad2e7c6b33 100644 --- a/src/NetworkManagerUtils.c +++ b/src/NetworkManagerUtils.c @@ -1862,7 +1862,7 @@ monotonic_timestamp_get (struct timespec *tp) gint64 nm_utils_get_monotonic_timestamp_ns (void) { - struct timespec tp; + struct timespec tp = { 0 }; monotonic_timestamp_get (&tp); @@ -1889,7 +1889,7 @@ nm_utils_get_monotonic_timestamp_ns (void) gint64 nm_utils_get_monotonic_timestamp_us (void) { - struct timespec tp; + struct timespec tp = { 0 }; monotonic_timestamp_get (&tp); @@ -1916,7 +1916,7 @@ nm_utils_get_monotonic_timestamp_us (void) gint64 nm_utils_get_monotonic_timestamp_ms (void) { - struct timespec tp; + struct timespec tp = { 0 }; monotonic_timestamp_get (&tp); @@ -1943,7 +1943,7 @@ nm_utils_get_monotonic_timestamp_ms (void) gint32 nm_utils_get_monotonic_timestamp_s (void) { - struct timespec tp; + struct timespec tp = { 0 }; monotonic_timestamp_get (&tp); return (((gint64) tp.tv_sec) + monotonic_timestamp_offset_sec); -- cgit v1.2.1 From 43b4c8f8268fce031b7a73c4ffa5830e8a3b75ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Klime=C5=A1?= Date: Thu, 4 Dec 2014 17:17:12 +0100 Subject: platform: ignore nm_platform_ip4_route_add/delete return value Coverity: Defect type: CHECKED_RETURN --- src/platform/nm-platform.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c index 7433ccd186..04ac4ce089 100644 --- a/src/platform/nm-platform.c +++ b/src/platform/nm-platform.c @@ -1801,8 +1801,10 @@ nm_platform_ip4_address_sync (int ifindex, const GArray *known_addresses, guint3 * The workaround is to configure different device priorities via ipv4.route-metric. */ network = nm_utils_ip4_address_clear_host_address (known_address->address, known_address->plen); - nm_platform_ip4_route_add (ifindex, NM_IP_CONFIG_SOURCE_KERNEL, network, known_address->plen, 0, known_address->address, device_route_metric, 0); - nm_platform_ip4_route_delete (ifindex, network, known_address->plen, NM_PLATFORM_ROUTE_METRIC_IP4_DEVICE_ROUTE); + (void) nm_platform_ip4_route_add (ifindex, NM_IP_CONFIG_SOURCE_KERNEL, network, known_address->plen, + 0, known_address->address, device_route_metric, 0); + (void) nm_platform_ip4_route_delete (ifindex, network, known_address->plen, + NM_PLATFORM_ROUTE_METRIC_IP4_DEVICE_ROUTE); } return TRUE; @@ -2070,7 +2072,7 @@ nm_platform_ip4_route_sync (int ifindex, const GArray *known_routes) route = &g_array_index (routes, NMPlatformIP4Route, i); if (!array_contains_ip4_route (known_routes, route)) - nm_platform_ip4_route_delete (ifindex, route->network, route->plen, route->metric); + (void) nm_platform_ip4_route_delete (ifindex, route->network, route->plen, route->metric); } if (!known_routes) { -- cgit v1.2.1 From 28599331e3e0ef7374ac3ac46e67125a4b91e521 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Klime=C5=A1?= Date: Thu, 4 Dec 2014 17:19:41 +0100 Subject: callout: ignore waitpid() return value Coverity: Defect type: CHECKED_RETURN --- callouts/nm-dispatcher.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/callouts/nm-dispatcher.c b/callouts/nm-dispatcher.c index dafe4f6e63..0cd2531dda 100644 --- a/callouts/nm-dispatcher.c +++ b/callouts/nm-dispatcher.c @@ -296,7 +296,7 @@ script_timeout_cb (gpointer user_data) if (kill (script->pid, 0) == 0) kill (script->pid, SIGKILL); - waitpid (script->pid, NULL, 0); + (void) waitpid (script->pid, NULL, 0); script->error = g_strdup_printf ("Script '%s' timed out.", script->script); script->result = DISPATCH_RESULT_TIMEOUT; -- cgit v1.2.1 From b11416de6a07ef696e287d7891c5979fcf4b1abb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Klime=C5=A1?= Date: Thu, 4 Dec 2014 17:39:26 +0100 Subject: libnm: check pspec before accessing it in handle_property_changed() Fixes: 1f8ec6122e5ae950da7eb3e6b145609f08685c71 Coverity: libnm/nm-object.c:926: var_deref_op: Dereferencing null pointer "pspec". libnm/nm-object.c:924: var_deref_op: Dereferencing null pointer "pspec". --- libnm/nm-object.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libnm/nm-object.c b/libnm/nm-object.c index f02c09c2e2..391166b29b 100644 --- a/libnm/nm-object.c +++ b/libnm/nm-object.c @@ -919,7 +919,7 @@ handle_property_changed (NMObject *self, const char *dbus_name, g_free (s); } - if (pi->object_type) { + if (pspec && pi->object_type) { if (g_variant_is_of_type (value, G_VARIANT_TYPE_OBJECT_PATH)) success = handle_object_property (self, pspec->name, value, pi, synchronously); else if (g_variant_is_of_type (value, G_VARIANT_TYPE ("ao"))) -- cgit v1.2.1 From 448b073bda92f5200303e4c5841e9031c4d5aadd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Klime=C5=A1?= Date: Thu, 4 Dec 2014 17:54:22 +0100 Subject: bluetooth: the code cannot be reached because either GSM or CDMA is present. It is checked just above. Coverity: Defect type: DEADCODE src/devices/bluetooth/nm-device-bt.c:312: dead_error_line: Execution cannot reach this statement: "fallback_prefix = dcgettext...". --- src/devices/bluetooth/nm-device-bt.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/devices/bluetooth/nm-device-bt.c b/src/devices/bluetooth/nm-device-bt.c index 2cf2794da6..689f37c9b4 100644 --- a/src/devices/bluetooth/nm-device-bt.c +++ b/src/devices/bluetooth/nm-device-bt.c @@ -304,12 +304,11 @@ complete_connection (NMDevice *device, fallback_prefix = _("GSM connection"); if (!nm_setting_gsm_get_number (s_gsm)) g_object_set (G_OBJECT (s_gsm), NM_SETTING_GSM_NUMBER, "*99#", NULL); - } else if (s_cdma) { + } else { fallback_prefix = _("CDMA connection"); if (!nm_setting_cdma_get_number (s_cdma)) g_object_set (G_OBJECT (s_cdma), NM_SETTING_GSM_NUMBER, "#777", NULL); - } else - fallback_prefix = _("DUN connection"); + } } else { g_set_error_literal (error, NM_CONNECTION_ERROR, -- cgit v1.2.1 From 49bbafbb160740c0a5634738745748178d7e8308 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Klime=C5=A1?= Date: Thu, 4 Dec 2014 18:05:24 +0100 Subject: utils: fix converting milliseconds to microseconds Coverity: Defect type: CONSTANT_EXPRESSION_RESULT /src/NetworkManagerUtils.c:726: result_independent_of_operands: "18446744073709551615UL /* 9223372036854775807L * 2UL + 1UL */ < (gulong)sleep_duration_msec * 1000UL" is always false regardless of the values of its operands. This occurs as the logical first operand of '?:'. --- src/NetworkManagerUtils.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/NetworkManagerUtils.c b/src/NetworkManagerUtils.c index ad2e7c6b33..2ce6e1a396 100644 --- a/src/NetworkManagerUtils.c +++ b/src/NetworkManagerUtils.c @@ -486,6 +486,17 @@ nm_utils_kill_child_async (pid_t pid, int sig, guint64 log_domain, g_child_watch_add (pid, _kc_cb_watch_child, data); } +static inline gulong +_sleep_duration_convert_ms_to_us (guint32 sleep_duration_msec) +{ + if (sleep_duration_msec > 0) { + guint64 x = (gint64) sleep_duration_msec * (guint64) 1000L; + + return x < G_MAXULONG ? (gulong) x : G_MAXULONG; + } + return G_USEC_PER_SEC / 20; +} + /* nm_utils_kill_child_sync: * @pid: process id to kill * @sig: signal to sent initially. If 0, no signal is sent. If %SIGKILL, the @@ -569,7 +580,7 @@ nm_utils_kill_child_sync (pid_t pid, int sig, guint64 log_domain, const char *lo gulong sleep_time, sleep_duration_usec; int loop_count = 0; - sleep_duration_usec = (sleep_duration_msec <= 0) ? (G_USEC_PER_SEC / 20) : MIN (G_MAXULONG, ((gint64) sleep_duration_msec) * 1000L); + sleep_duration_usec = _sleep_duration_convert_ms_to_us (sleep_duration_msec); wait_until = wait_before_kill_msec <= 0 ? 0 : wait_start_us + (((gint64) wait_before_kill_msec) * 1000L); while (TRUE) { @@ -723,7 +734,7 @@ nm_utils_kill_process_sync (pid_t pid, guint64 start_time, int sig, guint64 log_ wait_start_us = nm_utils_get_monotonic_timestamp_us (); - sleep_duration_usec = (sleep_duration_msec == 0) ? (G_USEC_PER_SEC / 20) : MIN (G_MAXULONG, ((gulong) sleep_duration_msec) * 1000UL); + sleep_duration_usec = _sleep_duration_convert_ms_to_us (sleep_duration_msec); wait_until = wait_start_us + (((gint64) wait_before_kill_msec) * 1000L); while (TRUE) { -- cgit v1.2.1