After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 734466 - "nmcli dev wifi" crashes with multiple wifis
"nmcli dev wifi" crashes with multiple wifis
Product: NetworkManager
Classification: Platform
Component: nmcli
git master
Other Linux
: Normal normal
: ---
Assigned To: NetworkManager maintainer(s)
NetworkManager maintainer(s)
Depends on:
Reported: 2014-08-08 05:51 UTC by Martin Pitt
Modified: 2014-08-18 12:07 UTC
See Also:
GNOME target: ---
GNOME version: ---

cli: fix crash in `nmcli device wifi` with multiple wifi devices (1.36 KB, patch)
2014-08-08 11:19 UTC, Thomas Haller
rejected Details | Review

Description Martin Pitt 2014-08-08 05:51:53 UTC
While updating python-dbusmock's NetworkManager template for 0.9.10 ( I noticed a regression in nmcli: It now crashes if there is more than one Device.Wireless.

$ LANG= nmcli dev wifi
SSID                              BSSID               MODE             FREQ       RATE       SIGNAL   SECURITY   ACTIVE  
'AP_0'                            00:23:F8:7E:12:BA   Unknown          2425 MHz   5 MB/s     82       WPA WPA2   no      
'AP_2'                            00:23:F8:7E:12:BC   Infrastructure   2425 MHz   5 MB/s     82       WPA WPA2   no      
'AP_1'                            00:23:F8:7E:12:BB   Ad-Hoc           2425 MHz   5 MB/s     82       WPA WPA2   no      

With 0.9.10 and current git master:

$ LANG= nmcli dev wifi
   AP_0  N/A   0     5 Mbit/s  82      ▂▄▆█  WPA1 WPA2 
Segmentation fault (core dumped)

Backtrace from current git master with -O0:

Program received signal SIGSEGV, Segmentation fault.
0x000000000044f586 in print_required_fields (nmc=0x671e80 <nm_cli>, 
    field_values=0x6c0b50) at utils.c:963
963		for (i = 0; i < fields.indices->len; i++) {
(gdb) bt full
  • #0 print_required_fields
    at utils.c line 963
  • #1 print_data
    at utils.c line 1079
  • #2 show_acces_point_info
    at devices.c line 1700
  • #3 do_device_wifi_list
    at devices.c line 1895
  • #4 do_device_wifi
    at devices.c line 2410
  • #5 do_devices
    at devices.c line 2782
  • #6 do_cmd
    at nmcli.c line 133
  • #7 parse_command_line
    at nmcli.c line 266
  • #8 start
    at nmcli.c line 460
  • #9 g_main_context_dispatch
    from /lib/x86_64-linux-gnu/
  • #10 ??
    from /lib/x86_64-linux-gnu/
  • #11 g_main_loop_run
    from /lib/x86_64-linux-gnu/
  • #12 main
    at nmcli.c line 503

Comment 1 Martin Pitt 2014-08-08 05:59:18 UTC
The problem can be seen in clients/cli/devices.c do_device_wifi_list(). We land in this loop at the bottom of the function:

                        for (i = 0; devices[i]; i++) {
                                NMDevice *dev = devices[i];

                                /* Main header name */
                                nmc->print_fields.header_name = (char *) construct_header_name (base_hdr,
                                                                                                nm_device_get_iface (dev));
                                if (NM_IS_DEVICE_WIFI (dev))
                                        show_acces_point_info (dev, nmc);

In the first iteration right before calling show_acces_point_info() we still have a valid indices:

(gdb) p nmc->print_fields
$2 = {indices = 0x67a4f0, 
  header_name = 0x671b80 <header_name> "Wi-Fi scan list (wlan0)", indent = 0}

show_acces_point_info() does show wlan0, but hten sets indices to NULL:

(gdb) n
   AP_0  N/A   0     5 Mbit/s  82      ▂▄▆█  WPA1 WPA2 
1888				for (i = 0; devices[i]; i++) {
(gdb) p nmc->print_fields
$3 = {indices = 0x0, header_name = 0x671b80 <header_name> "Wi-Fi scan list (wlan0)", 
  indent = 0}

This causes the next iteration to crash. A bisect of mine this morning pointed to commit 0221971; that might not be entirely accurate as at that time dbusmock didn't yet have the required "AccessPoints" property yet, but it certainly looks related.
Comment 2 Martin Pitt 2014-08-08 06:04:23 UTC
If you don't have multiple WIFI devices, this can be reproduced easily with the latest python-dbusmock (from git, or I'm just about to release 0.11.1 with the updated NM template for 0.9.10), and running this selftest in the source tree:

PYTHONPATH=. python3 tests/ TestNetworkManager.test_two_wifi_with_accesspoints

You can start a shell right after setting up the two wifis with APs with, and then just call nmcli; the system one, or e. g. the one from the NM git build with

  LD_LIBRARY_PATH=NetworkManager/libnm/.libs/ gdb --args NetworkManager/clients/cli/.libs/nmcli dev wifi

Alternatively you could use mac80211_hwsim and hostapd to set up two wifis, but that's more complicated to set up.

Note that I don't think it is an issue with the mock: I added a new test case test_one_wifi_with_accesspoints() which works fine. And test_two_wifi_with_accesspoints() works if I comment out either of the two wifis.
Comment 3 Thomas Haller 2014-08-08 11:19:58 UTC
Created attachment 282900 [details] [review]
cli: fix crash in `nmcli device wifi` with multiple wifi devices

Reported-by: Martin Pitt <>
Signed-off-by: Thomas Haller <>
Comment 4 Jiri Klimes 2014-08-18 12:06:06 UTC
Review of attachment 282900 [details] [review]:

The patch fixes the crash, however it causes duplicates in the output.
Comment 5 Jiri Klimes 2014-08-18 12:07:25 UTC
I have pushed another fix to master branch:
26eafd3 trivial: fix a typo in show_access_point_info() function name
45358f5 cli: fix crash in `nmcli device wifi` with multiple wifi devices (bgo #734466)