]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
libsystemd-network: do not trigger assertion by sd_*_is_running() with NULL
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 9 Apr 2024 19:03:46 +0000 (04:03 +0900)
committerLuca Boccassi <luca.boccassi@gmail.com>
Wed, 10 Apr 2024 21:53:55 +0000 (22:53 +0100)
If systemd is built with developer mode, previously they trigger
hard assertions. Even built with release mode, we should not log about
that. Let's silently accept NULL and return false.

Prompted by https://github.com/systemd/systemd/pull/32166#issuecomment-2044710151.

src/libsystemd-network/sd-dhcp6-client.c
src/libsystemd-network/sd-ipv4acd.c
src/libsystemd-network/sd-ipv4ll.c
src/libsystemd-network/sd-radv.c

index 5a26102e232b0fe4567fd906c19cd2ea5f8b714a..229ceef78362bf4f08fb5498f5bddd3d04ede8df 100644 (file)
@@ -1417,7 +1417,8 @@ int sd_dhcp6_client_stop(sd_dhcp6_client *client) {
 }
 
 int sd_dhcp6_client_is_running(sd_dhcp6_client *client) {
-        assert_return(client, -EINVAL);
+        if (!client)
+                return false;
 
         return client->state != DHCP6_STATE_STOPPED;
 }
index 1a9a8f10ab61008d6629d2033de0e4aff0e6c660..51d2b2219dd7b35a7326c6bd9922b3e36c5a09e3 100644 (file)
@@ -564,7 +564,8 @@ int sd_ipv4acd_get_address(sd_ipv4acd *acd, struct in_addr *address) {
 }
 
 int sd_ipv4acd_is_running(sd_ipv4acd *acd) {
-        assert_return(acd, false);
+        if (!acd)
+                return false;
 
         return acd->state != IPV4ACD_STATE_INIT;
 }
index a29279e6afc5210337ce19bfa9323e13ddceb890..5bf98332a9f184e6968ace16bd96b5c08a7a5fdf 100644 (file)
@@ -206,7 +206,8 @@ int sd_ipv4ll_set_address_seed(sd_ipv4ll *ll, uint64_t seed) {
 }
 
 int sd_ipv4ll_is_running(sd_ipv4ll *ll) {
-        assert_return(ll, false);
+        if (!ll)
+                return false;
 
         return sd_ipv4acd_is_running(ll->acd);
 }
index 71e7a71897024b6abc63588133c7ba7b4c1769b2..cde45388b7ce763f6caf34136ab8a395abf58568 100644 (file)
@@ -81,7 +81,8 @@ sd_event *sd_radv_get_event(sd_radv *ra) {
 }
 
 int sd_radv_is_running(sd_radv *ra) {
-        assert_return(ra, false);
+        if (!ra)
+                return false;
 
         return ra->state != RADV_STATE_IDLE;
 }