nmcli: fix crash in "nmcli device monitor"

Fix the following crash:

  $ nmcli device monitor a
  Error: Device 'a' not found.
  Segmentation fault (core dumped)

Found by coverity:

  1. NetworkManager-1.41.3/src/nmcli/devices.c:0: scope_hint: In function 'do_devices_monitor'
  2. NetworkManager-1.41.3/src/nmcli/devices.c:2932:28: warning[-Wanalyzer-null-dereference]: dereference of NULL 'devices'
     2930|       }
     2931|
     2932|->     for (i = 0; i < devices->len; i++)
     2933|           device_watch(nmc, g_ptr_array_index(devices, i));
     2934|

Fixes: 2074b28976 ('nmcli/devices: return GPtrArray instead of GSList from get_device_list()')
This commit is contained in:
Beniamino Galvani 2022-10-19 11:41:13 +02:00
parent 4ffb7cba7b
commit 40897db056

View file

@ -2920,6 +2920,8 @@ do_devices_monitor(const NMCCommand *cmd, NmCli *nmc, int argc, const char *cons
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
return;
}
if (!devices)
return;
} else {
/* No devices specified. Monitor all. */
devices = nm_client_get_devices(nmc->client);