From 40897db05614df8ef3cf0fd3dc407fabcca5536e Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Wed, 19 Oct 2022 11:41:13 +0200 Subject: [PATCH] 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: 2074b2897627 ('nmcli/devices: return GPtrArray instead of GSList from get_device_list()') --- src/nmcli/devices.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/nmcli/devices.c b/src/nmcli/devices.c index b449383034..f26519bfcf 100644 --- a/src/nmcli/devices.c +++ b/src/nmcli/devices.c @@ -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);