Commit Graph

23752 Commits

Author SHA1 Message Date
Thomas Haller
66088a09b2 libnm: when stringifying policy routing rule place "not" specifier after "priority"
Otherwise, it just looks odd:

  "not priority 31265 from 0.0.0.0/0 fwmark 0xcb87 table 52103"

Better is:

  "priority 31265 not from 0.0.0.0/0 fwmark 0xcb87 table 52103"

The "not" specifier should come after the priority. It makes more sense
to read it that way. As far as parsing the string is concerned, the
order does not matter. So this change in behavior is no problem.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/228
2019-08-05 10:16:10 +02:00
Thomas Haller
d4fabd728a cli: merge branch 'th/nmcli-add-and-activate-cleanup'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/227
2019-08-05 10:11:01 +02:00
Thomas Haller
b298f2e605 cli: use cleanup macro for freeing AddAndActivateInfo
We should prefer the cleanup macors nm_auto*() because they express
ownership in code.

Also, they allow to return early without additional cleanup code.
That way we can refactor if-else blocks.

Also, in cases where we intentionally pass on the reference, we use
g_steal_pointer(), which literally spells out what happens in code.
2019-08-05 10:11:01 +02:00
Thomas Haller
cf6cd06422 cli: add helper function to create and initialize AddAndActivateInfo struct
Also use gslice allocator instead of malloc as the size of
AddAndActivateInfo is fixed and known beforehand.
2019-08-05 10:11:01 +02:00
Beniamino Galvani
956ffb7e96 settings: fix memory leak
Fixes: d35d3c468a
2019-08-05 09:36:12 +02:00
Thomas Haller
1634fff1ad settings: fix registering AgentManager.RegisterWithCapabilities() twice
Fixes: 297d4985ab
2019-08-03 18:33:55 +02:00
Thomas Haller
85c26341a2 wireguard: fix use-after free in _peers_remove() 2019-08-03 12:27:57 +02:00
Thomas Haller
eea8bbd9ae libnm: fix leak in NMSettingWireGuard's update_one_secret() 2019-08-03 11:25:10 +02:00
Lubomir Rintel
377a775a2a merge: branch 'lr/nm-d-wifi-con-update'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/219
2019-08-02 23:00:55 +02:00
Lubomir Rintel
a4740fb82a cli: update the existing connection on "dev wifi connect"
If we find a matching connection, ensure it's exactly as we want it
before actually proceeding to activate it. Fixes this problem:

  # nmcli dev wifi connect "Network of Doom" password santa <-- bad
  Error: Connection activation failed: (7) Invalid secrets
  # nmcli dev wifi connect "Network of Doom" password satan <-- correct
  Error: Connection activation failed: (7) Invalid secrets

The password is now correct, but nmcli chose to re-activate the wrong
connection it created previously.
2019-08-02 23:00:26 +02:00
Lubomir Rintel
bc614783f0 cli: take a reference to device in AddAndActivateInfo
The device could vanish in between.
2019-08-02 23:00:26 +02:00
Lubomir Rintel
69ed759ddf cli: remove an unnecessary condition
Do not check for password when creating a simple connection object for
"nmcli dev wifi connect".

This makes no difference in practice. The password is checked for
existence later on and the connection instance is created anyway. This
just makes things look a bit more consistent.
2019-08-02 23:00:26 +02:00
Lubomir Rintel
cc3681c96c cli: (trivial) rename do_device_wifi_connect_network() to do_device_wifi_connect()
This is consistent with the surrounding code and avoids lines
unnecessarily too wide.
2019-08-02 23:00:26 +02:00
Thomas Haller
722b167953 supplicant: mark static arrays as const and static in "nm-supplicant-settings-verify.c"
They should be "static" and only visible to this source file.

Also, they should be "const", that allows the linker to place them
into read-only memory.
2019-08-02 18:18:30 +02:00
Thomas Haller
55143dad95 supplicant: don't put binary data in error message for supplicant
For better or worse, the API does not require the value to be a
UTF-8 string. We cannot just concatenate binary to a string.
Instead, backslash escape it with utf8safe-escape.

Also, this will shut up a (wrong) coverity warning at this place.
2019-08-02 18:18:30 +02:00
Thomas Haller
9ed26de3da supplicant: fix nm_supplicant_settings_verify_setting() honoring the string length
We must not just pretend that the value is a NULL terminated string.
That's why we have the length argument.
2019-08-02 18:18:30 +02:00
Thomas Haller
526601e4f3 device/bluetooth: explicitly ignore return value of ioctl() in nm_bluez5_dun_cleanup()
Coverity doesn't like us not checking the result.
2019-08-02 18:10:58 +02:00
Thomas Haller
643bc4ca22 libnm: remove dead code in nm_team_setting_config_get()
I was aware that this code is not reachable. But for consistency, it
seems better to be explict about it (to avoid future bugs when refactoring).

Anyway, Coverity complains about it. So assert instead.
2019-08-02 18:10:58 +02:00
Thomas Haller
88bcf87ad9 device: trigger a connectivity check when device disconnects
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/219

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/225
2019-08-02 17:50:44 +02:00
Thomas Haller
1b30797bc1 core: assert for valid arguments in _addresses_sort_cmp()
Coverity thinks that the arguments could be %NULL. Add an assertion,
hoping to silence coverity.
2019-08-02 17:13:16 +02:00
Beniamino Galvani
50ae9c936c tui: newt: remove NULL checks after dereference
priv->start_buttons and priv->end_buttons are initialized at
construction and never changed and so the checks are not needed.
2019-08-02 16:26:34 +02:00
Beniamino Galvani
a32976568c n-dhcp4: remove dead code
Reported by coverity.
2019-08-02 16:26:33 +02:00
Thomas Haller
483de2bb93 platform/tests: relax assertion for platform signal in test_slave()
Seen on gitlab-ci.

  NMPlatformSignalAssert: ../src/platform/tests/test-link.c:260, test_slave(): failure to accept signal [0,2] times: link-changed-changed ifindex 15 (3 times received)
  ERROR: src/platform/tests/test-link-linux - too few tests run (expected 76, got 6)
  ERROR: src/platform/tests/test-link-linux - exited with status 133 (terminated by signal 5?)
2019-08-02 13:34:56 +02:00
Thomas Haller
23fa1b3272 adsl: avoid coverity false-positive when using strcpy() for interface name
CID 59391 (#1 of 1): Copy into fixed size buffer (STRING_OVERFLOW)
  31. fixed_size_dest: You might overrun the 16-character fixed-size string be.ifspec.spec.ifname by copying priv->nas_ifname without checking the length.
2019-08-02 11:47:06 +02:00
Thomas Haller
9f4302e132 libnm: fix parsing invalid "pvid" attribute in GVariant in _nm_utils_bridge_vlans_from_dbus()
Complained by Coverity.
2019-08-02 11:47:06 +02:00
Thomas Haller
9e7ca3e091 n-dhcp4: avoid "-Werror=declaration-after-statement" warning with static_assert
When we build n-dhcp4 for NetworkManager we get a compiler warning.
This can also be reproduced by building n-dhcp4 alone:

  $ CFLAGS='-Werror=declaration-after-statement' meson build && ninja -C build
  ...
  [36/47] Compiling C object 'src/25a6634@@ndhcp4-private@sta/n-dhcp4-outgoing.c.o'.
  FAILED: src/25a6634@@ndhcp4-private@sta/n-dhcp4-outgoing.c.o
  ccache cc -Isrc/25a6634@@ndhcp4-private@sta -Isrc -I../src -Isubprojects/c-list/src -I../subprojects/c-list/src -Isubprojects/c-siphash/src -I../subprojects/c-siphash/src -Isubprojects/c-stdaux/src -I../subprojects/c-stdaux/src -fdiagnostics-color=always -pipe -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -std=c11 -g -D_GNU_SOURCE -Werror=declaration-after-statement -fPIC -fvisibility=hidden -fno-common -MD -MQ 'src/25a6634@@ndhcp4-private@sta/n-dhcp4-outgoing.c.o' -MF 'src/25a6634@@ndhcp4-private@sta/n-dhcp4-outgoing.c.o.d' -o 'src/25a6634@@ndhcp4-private@sta/n-dhcp4-outgoing.c.o' -c ../src/n-dhcp4-outgoing.c
  ../src/n-dhcp4-outgoing.c: In function ‘n_dhcp4_outgoing_new’:
  ../src/n-dhcp4-outgoing.c:63:9: error: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]
     63 |         static_assert(N_DHCP4_NETWORK_IP_MINIMUM_MAX_SIZE >= N_DHCP4_OUTGOING_MAX_PHDR +
        |         ^~~~~~~~~~~~~
2019-08-02 11:34:20 +02:00
Thomas Haller
c8cee413dd n-acd: fix leaking socket handle in n_acd_socket_new() when setsockopt() fails
Found by Coverity.
2019-08-02 11:26:25 +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
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
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
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