Commit Graph

23863 Commits

Author SHA1 Message Date
Thomas Haller
b6d9693705 all: merge branch 'th/coverity'
Various fixes for Coverity. For the most part, these are refactorings
to avoid false positive warnings.

(cherry picked from commit d3bd7b9bee)
2019-08-02 11:12:52 +02:00
Thomas Haller
d3bd7b9bee all: merge branch 'th/coverity'
Various fixes for Coverity. For the most part, these are refactorings
to avoid false positive warnings.
2019-08-02 11:11:24 +02:00
Thomas Haller
bedafc661a shared: refactor nm_utils_g_slist_strlist_cmp() to avoid dead-code warning from Coverity
Coverity sees that "return 0" cannot be reached. Refactor the code,
to avoid the warning.

(cherry picked from commit 8fb954b81d)
2019-08-02 11:10:51 +02:00
Thomas Haller
14debab83a shared: try avoid coverity warning in _nm_utils_user_data_unpack()
Coverity says

  CID 202453 (#1 of 1): Wrong sizeof argument (SIZEOF_MISMATCH)suspicious_sizeof:
  Passing argument user_data of type gconstpointer and argument (gsize)nargs * 8UL /* sizeof (gconstpointer) */ to function g_slice_free1 is suspicious.

Let's pass instead the "data" pointer. It's the same, but maybe that
avoids the warning.

(cherry picked from commit d76df4c139)
2019-08-02 11:10:51 +02:00
Thomas Haller
709570b8e9 shared: explicitly ignore return value of g_utf8_validate()
Coverity doesn't like us ignoring the return value, although
we really only care about the "p" output pointer.

Try casting the result to (void), maybe that silences Coverity.

(cherry picked from commit e6fa3ce2df)
2019-08-02 11:10:51 +02:00
Thomas Haller
2ecc7e8cb5 initrd: avoid coverity warning in parse_ip() about "Dereference before null check"
get_word() only moves the "argument" pointer forward. It never sets it
to %NULL. Also, above we already dereference argument, so Coverity thinks
that this NULL check indicates a bug.

Drop it to silence Coverity.

(cherry picked from commit 4596d7793c)
2019-08-02 11:10:51 +02:00
Thomas Haller
c347e81a1d libnm/keyfile: silence "Identical code for different branches" complaint in _read_setting_wireguard_peer()
That both branches of the "if" do the same, looks suspicious to Coverity.
Work around it by not doing it.

(cherry picked from commit e001424ae2)
2019-08-02 11:10:51 +02:00
Thomas Haller
e4001e50da device/wireguard: fix explicit_bzero() call on peers buffer in link_config()
Correctly warned by coverity.

(cherry picked from commit 458a2edbb2)
2019-08-02 11:10:51 +02:00
Thomas Haller
fec1c760ec device/adsl: restore brfd value on error in br2684_assign_vcc()
Warned by coverity: we assert above that brfd is -1, so we must always
restore it to -1 in the error case.

Technically, not a problem because socket() is documented to return
only -1 on error already. Apparently coverity does not believe that.

(cherry picked from commit 5b9a848a82)
2019-08-02 11:10:51 +02:00
Thomas Haller
702224ec0b core: assert for valid arguments in sort_captured_addresses() and _addresses_sort_cmp()
Coverity thinks that the arguments could be %NULL. Add an assertion,
hoping to silence coverity.

(cherry picked from commit 8988a12ade)
2019-08-02 11:10:50 +02:00
Thomas Haller
ee153744a9 libnm: avoid NM_CONST_MAX() in enum definition for NMTeamAttribute
This confuses coverity. Just use MAX(). MAX() is usually not preferred
as it evaluates the arguments more than once. But in this case, it is of
course fine.

  CID 202433 (#1 of 1): Unrecoverable parse warning (PARSE_ERROR)1.
  expr_not_constant: expression must have a constant value

(cherry picked from commit 186d559d63)
2019-08-02 11:10:50 +02:00
Thomas Haller
4952e945dc libnm: try to avoid coverity warning in assertion()
Coverity thinks that this could be NULL sometimes. Try to check for that
to shut up the warning.

(cherry picked from commit f61e274df9)
2019-08-02 11:10:50 +02:00
Thomas Haller
12321b1745 libnm: fix assertions in NMSettingVlan's priority API
Most of these functions did not ever return failure. The functions
were assertin that the input was valid (and then returned a special
value). But they did not fail under regular conditions.

Fix the gtk-doc for some of these to not claim to be able to fail.

For some (like nm_setting_vlan_add_priority_str() and
nm_setting_vlan_get_priority()), actually let them fail for valid
input (instead of asserting).

(cherry picked from commit b5793b74ca)
2019-08-02 11:10:50 +02:00
Thomas Haller
96c999e085 cli: fix type for loop variable in _get_fcn_vlan_xgress_priority_map()
Coverity correctly points out that nm_setting_vlan_get_num_priorities() can return
a negative value (-1 on assertion). Handle that by using the right integer type.

(cherry picked from commit af4a41cc4c)
2019-08-02 11:10:50 +02:00
Thomas Haller
650c0cd622 cli: fix dereferncing NULL pointer in parse_passwords() with empty file
Warned by coverity.

(cherry picked from commit ec982ceb8e)
2019-08-02 11:10:50 +02:00
Thomas Haller
ae1f6de899 cli: use gs_free_error in nmcli's "connections.c"
(cherry picked from commit bee0b20e3f)
2019-08-02 11:10:50 +02:00
Thomas Haller
7d5bbe5453 platform: drop checks for failure of nl80211_alloc_msg()
nl80211_alloc_msg() just allocates some memory, using glib's allocators.
Hence it cannot fail, and we don't need to check for that.

Drop the unnecessary %NULL checks.

(cherry picked from commit 990a7bee9d)
2019-08-02 11:10:50 +02:00
Thomas Haller
3c6252f4fd platform: avoid coverity warning about not checking nla_nest_start() result
Usually we check the result of nla_nest_start(). Also, in most cases where this
function would return %NULL, it's an actual bug. That is, because our netlink
message is allocated with a large buffer, and in most cases we append there a well
known, small amount of data.

To make coverity happy, handle the case and assert.

(cherry picked from commit 243458836a)
2019-08-02 11:10:50 +02:00
Thomas Haller
18f7a36ba1 core: fix coverity warning about memset() non-char value in assertion
CID 202432 (#1 of 1): Memset fill truncated (NO_EFFECT)
  bad_memset: Argument -559030611 in memset loses precision in memset(priv->connections_cached_list, -559030611, 8UL * (priv->connections_len + 1U)).

(cherry picked from commit 026739eb9f)
2019-08-02 11:10:50 +02:00
Thomas Haller
291ed80d6c ifcfg-rh: drop g_assert_not_reached() that clearly cannot be reached
Use nm_assert() which is disabled in production builds.

(cherry picked from commit 43575513ca)
2019-08-02 11:10:50 +02:00
Thomas Haller
2953408621 ifcfg-rh: drop unreachable code in make_wpa_setting()
This triggers a coverity warning because we above already
check that not all relevant keys are NULL together.

Work around warning by modifying the code.

(cherry picked from commit 210d7eb528)
2019-08-02 11:10:50 +02:00
Thomas Haller
40c5b79e36 core/trivial: fix whitespace
(cherry picked from commit 2ea3c23723)
2019-08-02 11:10:50 +02:00
Thomas Haller
8fb954b81d shared: refactor nm_utils_g_slist_strlist_cmp() to avoid dead-code warning from Coverity
Coverity sees that "return 0" cannot be reached. Refactor the code,
to avoid the warning.
2019-08-02 09:37:46 +02:00
Thomas Haller
d76df4c139 shared: try avoid coverity warning in _nm_utils_user_data_unpack()
Coverity says

  CID 202453 (#1 of 1): Wrong sizeof argument (SIZEOF_MISMATCH)suspicious_sizeof:
  Passing argument user_data of type gconstpointer and argument (gsize)nargs * 8UL /* sizeof (gconstpointer) */ to function g_slice_free1 is suspicious.

Let's pass instead the "data" pointer. It's the same, but maybe that
avoids the warning.
2019-08-02 09:30:35 +02:00
Thomas Haller
e6fa3ce2df shared: explicitly ignore return value of g_utf8_validate()
Coverity doesn't like us ignoring the return value, although
we really only care about the "p" output pointer.

Try casting the result to (void), maybe that silences Coverity.
2019-08-02 09:27:52 +02:00
Thomas Haller
4596d7793c initrd: avoid coverity warning in parse_ip() about "Dereference before null check"
get_word() only moves the "argument" pointer forward. It never sets it
to %NULL. Also, above we already dereference argument, so Coverity thinks
that this NULL check indicates a bug.

Drop it to silence Coverity.
2019-08-02 09:24:01 +02:00
Thomas Haller
e001424ae2 libnm/keyfile: silence "Identical code for different branches" complaint in _read_setting_wireguard_peer()
That both branches of the "if" do the same, looks suspicious to Coverity.
Work around it by not doing it.
2019-08-02 09:19:06 +02:00
Thomas Haller
458a2edbb2 device/wireguard: fix explicit_bzero() call on peers buffer in link_config()
Correctly warned by coverity.
2019-08-02 09:16:34 +02:00
Thomas Haller
5b9a848a82 device/adsl: restore brfd value on error in br2684_assign_vcc()
Warned by coverity: we assert above that brfd is -1, so we must always
restore it to -1 in the error case.

Technically, not a problem because socket() is documented to return
only -1 on error already. Apparently coverity does not believe that.
2019-08-02 09:14:33 +02:00
Thomas Haller
8988a12ade core: assert for valid arguments in sort_captured_addresses() and _addresses_sort_cmp()
Coverity thinks that the arguments could be %NULL. Add an assertion,
hoping to silence coverity.
2019-08-02 09:14:33 +02:00
Thomas Haller
186d559d63 libnm: avoid NM_CONST_MAX() in enum definition for NMTeamAttribute
This confuses coverity. Just use MAX(). MAX() is usually not preferred
as it evaluates the arguments more than once. But in this case, it is of
course fine.

  CID 202433 (#1 of 1): Unrecoverable parse warning (PARSE_ERROR)1.
  expr_not_constant: expression must have a constant value
2019-08-02 08:55:31 +02:00
Thomas Haller
f61e274df9 libnm: try to avoid coverity warning in assertion()
Coverity thinks that this could be NULL sometimes. Try to check for that
to shut up the warning.
2019-08-02 08:52:26 +02:00
Thomas Haller
b5793b74ca libnm: fix assertions in NMSettingVlan's priority API
Most of these functions did not ever return failure. The functions
were assertin that the input was valid (and then returned a special
value). But they did not fail under regular conditions.

Fix the gtk-doc for some of these to not claim to be able to fail.

For some (like nm_setting_vlan_add_priority_str() and
nm_setting_vlan_get_priority()), actually let them fail for valid
input (instead of asserting).
2019-08-02 08:46:40 +02:00
Thomas Haller
af4a41cc4c cli: fix type for loop variable in _get_fcn_vlan_xgress_priority_map()
Coverity correctly points out that nm_setting_vlan_get_num_priorities() can return
a negative value (-1 on assertion). Handle that by using the right integer type.
2019-08-02 08:44:12 +02:00
Thomas Haller
ec982ceb8e cli: fix dereferncing NULL pointer in parse_passwords() with empty file
Warned by coverity.
2019-08-02 08:33:36 +02:00
Thomas Haller
bee0b20e3f cli: use gs_free_error in nmcli's "connections.c" 2019-08-02 08:30:56 +02:00
Thomas Haller
990a7bee9d platform: drop checks for failure of nl80211_alloc_msg()
nl80211_alloc_msg() just allocates some memory, using glib's allocators.
Hence it cannot fail, and we don't need to check for that.

Drop the unnecessary %NULL checks.
2019-08-02 08:10:22 +02:00
Thomas Haller
243458836a platform: avoid coverity warning about not checking nla_nest_start() result
Usually we check the result of nla_nest_start(). Also, in most cases where this
function would return %NULL, it's an actual bug. That is, because our netlink
message is allocated with a large buffer, and in most cases we append there a well
known, small amount of data.

To make coverity happy, handle the case and assert.
2019-08-02 08:06:29 +02:00
Thomas Haller
026739eb9f core: fix coverity warning about memset() non-char value in assertion
CID 202432 (#1 of 1): Memset fill truncated (NO_EFFECT)
  bad_memset: Argument -559030611 in memset loses precision in memset(priv->connections_cached_list, -559030611, 8UL * (priv->connections_len + 1U)).
2019-08-02 08:06:29 +02:00
Thomas Haller
43575513ca ifcfg-rh: drop g_assert_not_reached() that clearly cannot be reached
Use nm_assert() which is disabled in production builds.
2019-08-02 08:06:29 +02:00
Thomas Haller
210d7eb528 ifcfg-rh: drop unreachable code in make_wpa_setting()
This triggers a coverity warning because we above already
check that not all relevant keys are NULL together.

Work around warning by modifying the code.
2019-08-02 08:06:18 +02:00
Thomas Haller
2ea3c23723 core/trivial: fix whitespace 2019-08-01 17:28:58 +02:00
Thomas Haller
f804bc7007 shared: fix non-serious bug with bogus condition in assertion in nm_key_file_db_ref()
(cherry picked from commit 9a229241f9)
2019-08-01 17:25:37 +02:00
Thomas Haller
9a229241f9 shared: fix non-serious bug with bogus condition in assertion in nm_key_file_db_ref() 2019-08-01 17:24:55 +02:00
Thomas Haller
d84d1db39e core/lldp: minor cleanup in _lldp_attr_*()
- use nm_g_variant_unref_floating()

- rename _lldp_attr_take_str_ptr() to _lldp_attr_set_str_take().
  The new name has the same "_lldp_attr_set_" prefix as other setters.
  Also, with the previous name it is unclear why it takes a "str-ptr".

- setting the same attribute multiple times, ignores all but the first
  value. Avoid cloning the string in that case, and explicitly choose
  the set or take function.

(cherry picked from commit 0fbb54839e)
2019-08-01 15:20:57 +02:00
Thomas Haller
273f0b5416 core/lldp: fix memleak in _lldp_attr_take_str_ptr()
Valgrind complains:

  ==26355== 32 bytes in 2 blocks are definitely lost in loss record 2,829 of 6,716
  ==26355==    at 0x4838748: malloc (vg_replace_malloc.c:308)
  ==26355==    by 0x483AD63: realloc (vg_replace_malloc.c:836)
  ==26355==    by 0x4F6AD4F: g_realloc (in /usr/lib64/libglib-2.0.so.0.6000.6)
  ==26355==    by 0x4F87B33: ??? (in /usr/lib64/libglib-2.0.so.0.6000.6)
  ==26355==    by 0x4F87B96: g_string_sized_new (in /usr/lib64/libglib-2.0.so.0.6000.6)
  ==26355==    by 0x2D66E1: nm_utils_buf_utf8safe_escape (nm-shared-utils.c:1911)
  ==26355==    by 0x4113B0: lldp_neighbor_new (nm-lldp-listener.c:676)
  ==26355==    by 0x412788: process_lldp_neighbor (nm-lldp-listener.c:882)
  ==26355==    by 0x4135CF: lldp_event_handler (nm-lldp-listener.c:931)
  ==26355==    by 0x422CDB: lldp_callback (sd-lldp.c:50)
  ==26355==    by 0x4235F9: lldp_add_neighbor (sd-lldp.c:166)
  ==26355==    by 0x423679: lldp_handle_datagram (sd-lldp.c:189)
  ==26355==    by 0x423C8B: lldp_receive_datagram (sd-lldp.c:235)
  ==26355==    by 0x2F887A: source_dispatch (sd-event.c:2832)
  ==26355==    by 0x2FAD43: sd_event_dispatch (sd-event.c:3245)
  ==26355==    by 0x2D9237: event_dispatch (nm-sd.c:51)
  ==26355==    by 0x4F64EDC: g_main_context_dispatch (in /usr/lib64/libglib-2.0.so.0.6000.6)
  ==26355==    by 0x4F6526F: ??? (in /usr/lib64/libglib-2.0.so.0.6000.6)
  ==26355==    by 0x4F655A2: g_main_loop_run (in /usr/lib64/libglib-2.0.so.0.6000.6)
  ==26355==    by 0x140932: main (main.c:465)
  ==26355==

(cherry picked from commit ece270ea5f)
2019-08-01 15:20:57 +02:00
Thomas Haller
0fbb54839e core/lldp: minor cleanup in _lldp_attr_*()
- use nm_g_variant_unref_floating()

- rename _lldp_attr_take_str_ptr() to _lldp_attr_set_str_take().
  The new name has the same "_lldp_attr_set_" prefix as other setters.
  Also, with the previous name it is unclear why it takes a "str-ptr".

- setting the same attribute multiple times, ignores all but the first
  value. Avoid cloning the string in that case, and explicitly choose
  the set or take function.
2019-08-01 15:08:47 +02:00
Thomas Haller
ece270ea5f core/lldp: fix memleak in _lldp_attr_take_str_ptr()
Valgrind complains:

  ==26355== 32 bytes in 2 blocks are definitely lost in loss record 2,829 of 6,716
  ==26355==    at 0x4838748: malloc (vg_replace_malloc.c:308)
  ==26355==    by 0x483AD63: realloc (vg_replace_malloc.c:836)
  ==26355==    by 0x4F6AD4F: g_realloc (in /usr/lib64/libglib-2.0.so.0.6000.6)
  ==26355==    by 0x4F87B33: ??? (in /usr/lib64/libglib-2.0.so.0.6000.6)
  ==26355==    by 0x4F87B96: g_string_sized_new (in /usr/lib64/libglib-2.0.so.0.6000.6)
  ==26355==    by 0x2D66E1: nm_utils_buf_utf8safe_escape (nm-shared-utils.c:1911)
  ==26355==    by 0x4113B0: lldp_neighbor_new (nm-lldp-listener.c:676)
  ==26355==    by 0x412788: process_lldp_neighbor (nm-lldp-listener.c:882)
  ==26355==    by 0x4135CF: lldp_event_handler (nm-lldp-listener.c:931)
  ==26355==    by 0x422CDB: lldp_callback (sd-lldp.c:50)
  ==26355==    by 0x4235F9: lldp_add_neighbor (sd-lldp.c:166)
  ==26355==    by 0x423679: lldp_handle_datagram (sd-lldp.c:189)
  ==26355==    by 0x423C8B: lldp_receive_datagram (sd-lldp.c:235)
  ==26355==    by 0x2F887A: source_dispatch (sd-event.c:2832)
  ==26355==    by 0x2FAD43: sd_event_dispatch (sd-event.c:3245)
  ==26355==    by 0x2D9237: event_dispatch (nm-sd.c:51)
  ==26355==    by 0x4F64EDC: g_main_context_dispatch (in /usr/lib64/libglib-2.0.so.0.6000.6)
  ==26355==    by 0x4F6526F: ??? (in /usr/lib64/libglib-2.0.so.0.6000.6)
  ==26355==    by 0x4F655A2: g_main_loop_run (in /usr/lib64/libglib-2.0.so.0.6000.6)
  ==26355==    by 0x140932: main (main.c:465)
  ==26355==
2019-08-01 15:04:41 +02:00
Thomas Haller
72e604c8e4 device: avoid unnecessary check for existing device in release_slave() implementations 2019-08-01 14:56:07 +02:00
Beniamino Galvani
0581a53a46 merge: branch 'bg/ovs-restart-part2-rh1733709'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/216

https://bugzilla.redhat.com/show_bug.cgi?id=1733709
(cherry picked from commit 5f668b81d3)
2019-08-01 09:31:52 +02:00