]> git.ipfire.org Git - thirdparty/systemd.git/commit
libsystemd-network: propagate sd_event_default() failure 42263/head
authorChris Mason <clm@meta.com>
Fri, 22 May 2026 16:13:55 +0000 (09:13 -0700)
committerLennart Poettering <lennart@amutable.com>
Fri, 22 May 2026 20:20:03 +0000 (22:20 +0200)
commit3f0aa5852ec4f53f7412cd8b86fd9d064bebd108
treeacae2242df2dd9f31dbc11f8b9f76755827fb983
parent99aff237831f318a817ab2dd786ab3d80979c7bb
libsystemd-network: propagate sd_event_default() failure

Four *_attach_event helpers swallow sd_event_default() failures and
return success while leaving obj->event NULL:

    sd_dhcp_client_attach_event   (sd-dhcp-client.c)
    sd_dhcp6_client_attach_event  (sd-dhcp6-client.c)
    sd_ndisc_attach_event         (sd-ndisc.c)
    sd_radv_attach_event          (sd-radv.c)

Each contains the same copy-pasted typo in the NULL-event branch:

    r = sd_event_default(&obj->event);
    if (r < 0)
            return 0;          /* swallows -ENOMEM / -ECHILD */

The caller is told the attach succeeded, but obj->event is still
NULL. A subsequent *_start() then trips assert_return(obj->event,
-EINVAL) and returns a spurious -EINVAL (or aborts on assert-abort
builds), and any consumer of *_get_event() dereferences NULL.

The sibling helper sd_dhcp_server_attach_event already uses the
correct pattern:

    r = sd_event_default(&server->event);
    if (r < 0)
            return r;

Fix by returning r instead of 0 at each of the four sites so the
sd_event_default() errno is propagated to the caller and ownership
stays with the caller.

Assisted-by: kres (claude-opus-4-7)
Signed-off-by: Chris Mason <clm@meta.com>
src/libsystemd-network/sd-dhcp-client.c
src/libsystemd-network/sd-dhcp6-client.c
src/libsystemd-network/sd-ndisc.c
src/libsystemd-network/sd-radv.c