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: a8329587c8 ('device: fix bug when deactivating port connections asynchronously')
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
(cherry picked from commit 56099c5e14)
This commit is contained in:
Jan Vaclav 2026-04-07 12:31:36 +02:00
parent d73332cfc9
commit 99028b39a8

View file

@ -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)"));