From 56099c5e14043b9511cd76bf57bbc6c89c25bdb3 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 --- 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 919ec82e12..f8b0dad9c8 100644 --- a/src/core/devices/nm-device.c +++ b/src/core/devices/nm-device.c @@ -7234,7 +7234,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)"; @@ -7247,7 +7249,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)"));