GNOME Bugzilla – Bug 734466
"nmcli dev wifi" crashes with multiple wifis
Last modified: 2014-08-18 12:07:25 UTC
While updating python-dbusmock's NetworkManager template for 0.9.10 (https://launchpad.net/bugs/1328579) I noticed a regression in nmcli: It now crashes if there is more than one Device.Wireless. With 0.9.8.8: $ 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 * SSID MODE CHAN RATE SIGNAL BARS SECURITY 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
+ Trace 233935
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 * SSID MODE CHAN RATE SIGNAL BARS SECURITY 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.
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/test_networkmanager.py TestNetworkManager.test_two_wifi_with_accesspoints You can start a shell right after setting up the two wifis with APs with http://paste.ubuntu.com/7986081/, 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.
Created attachment 282900 [details] [review] cli: fix crash in `nmcli device wifi` with multiple wifi devices https://bugzilla.gnome.org/show_bug.cgi?id=734466 Reported-by: Martin Pitt <martinpitt@gnome.org> Signed-off-by: Thomas Haller <thaller@redhat.com>
Review of attachment 282900 [details] [review]: The patch fixes the crash, however it causes duplicates in the output.
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)