]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-dhcp-client: do not crash if sd_dhcp_client_send_release() is called with no lease 13696/head
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 2 Oct 2019 08:29:41 +0000 (10:29 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 2 Oct 2019 12:01:42 +0000 (14:01 +0200)
Again, a public function should not crash if called at an inopportune moment.

Also, make sure we don't call the function if we have no lease.

src/libsystemd-network/sd-dhcp-client.c
src/network/networkd-dhcp4.c

index 3f386db2f559e1bacc2a58da9a036a720f119faf..02f3569edca877a0b117417318a33a4fc2aa7603 100644 (file)
@@ -1895,6 +1895,7 @@ int sd_dhcp_client_start(sd_dhcp_client *client) {
 int sd_dhcp_client_send_release(sd_dhcp_client *client) {
         assert_return(client, -EINVAL);
         assert_return(client->state != DHCP_STATE_STOPPED, -ESTALE);
+        assert_return(client->lease, -EUNATCH);
 
         _cleanup_free_ DHCPPacket *release = NULL;
         size_t optoffset, optlen;
index 78cd24114021d350781bce40c2338224587d6370..db762163a88d7b7cd3e46e1db5e1797b07041963 100644 (file)
@@ -864,10 +864,10 @@ static int dhcp4_handler(sd_dhcp_client *client, int event, void *userdata) {
                                 return 0;
                         }
 
-                        if (link->network->dhcp_send_release)
-                                (void) sd_dhcp_client_send_release(client);
-
                         if (link->dhcp_lease) {
+                                if (link->network->dhcp_send_release)
+                                        (void) sd_dhcp_client_send_release(client);
+
                                 r = dhcp_lease_lost(link);
                                 if (r < 0) {
                                         link_enter_failed(link);