From 99028b39a87407f132af5c544f14c9aa8999beb5 Mon Sep 17 00:00:00 2001 From: Jan Vaclav Date: Tue, 7 Apr 2026 12:31:36 +0200 Subject: [PATCH] device: fix potential null dereference when releasing port find_port_info() can return NULL if the port is not registered. The code dereferenced `info->port_state` before the null check, which would crash. Move the null check before the dereference. Found by Coverity (CID: REVERSE_INULL). Fixes: a8329587c8bd ('device: fix bug when deactivating port connections asynchronously') Co-Authored-By: Claude Opus 4.6 (cherry picked from commit 56099c5e14043b9511cd76bf57bbc6c89c25bdb3) --- src/core/devices/nm-device.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/core/devices/nm-device.c b/src/core/devices/nm-device.c index a0cf1ee6d0..1bebdf1933 100644 --- a/src/core/devices/nm-device.c +++ b/src/core/devices/nm-device.c @@ -7149,7 +7149,9 @@ nm_device_controller_release_port(NMDevice *self, info = find_port_info(self, port); - if (info->port_state == PORT_STATE_ATTACHED) + if (!info) + port_state_str = "(not registered)"; + else if (info->port_state == PORT_STATE_ATTACHED) port_state_str = "(attached)"; else if (info->port_state == PORT_STATE_NOT_ATTACHED) port_state_str = "(not attached)"; @@ -7162,7 +7164,7 @@ nm_device_controller_release_port(NMDevice *self, "controller: release one port " NM_HASH_OBFUSCATE_PTR_FMT "/%s %s%s", NM_HASH_OBFUSCATE_PTR(port), nm_device_get_iface(port), - !info ? "(not registered)" : port_state_str, + port_state_str, release_type == RELEASE_PORT_TYPE_CONFIG_FORCE ? " (force-configure)" : (release_type == RELEASE_PORT_TYPE_CONFIG ? " (configure)" : "(no-config)"));