diff options
author | Daniel Wang <wonderfly@users.noreply.github.com> | 2017-05-24 05:05:49 -0700 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2017-05-24 14:05:49 +0200 |
commit | b23aec0d6b98bc99998786506a8769e1a1ea1841 (patch) | |
tree | e88ed60169d70b613aa8a96f7f4826a67d3b168b | |
parent | a083537e5d11bce68639c492eda33a7fe997d142 (diff) | |
download | systemd-b23aec0d6b98bc99998786506a8769e1a1ea1841.tar.gz systemd-b23aec0d6b98bc99998786506a8769e1a1ea1841.tar.bz2 systemd-b23aec0d6b98bc99998786506a8769e1a1ea1841.zip |
DHCP: Fail link_dhcp_set_routes promotely if no address is assigned from lease (#6009)
Currently the local variable `address` is unintialized if the DHCP lease
doesn't provide a router address (when r == -ENODATA). Thus the
subsequent call to route_scope_from_address will result in accessing an
unintialized variable.
As a matter of fact, sd-dhcp-client ignores DHCP leases without an
address so link_dhcp_set_routes probably will never be called without a
valid address.
-rw-r--r-- | src/network/networkd-dhcp4.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/network/networkd-dhcp4.c b/src/network/networkd-dhcp4.c index ae0f78daab..9229b5753c 100644 --- a/src/network/networkd-dhcp4.c +++ b/src/network/networkd-dhcp4.c @@ -77,6 +77,10 @@ static int link_set_dhcp_routes(Link *link) { if (!link->network->dhcp_use_routes) return 0; + r = sd_dhcp_lease_get_address(link->dhcp_lease, &address); + if (r < 0) + return log_link_warning_errno(link, r, "DHCP error: could not get address: %m"); + r = sd_dhcp_lease_get_router(link->dhcp_lease, &gateway); if (r < 0 && r != -ENODATA) return log_link_warning_errno(link, r, "DHCP error: could not get gateway: %m"); @@ -85,10 +89,6 @@ static int link_set_dhcp_routes(Link *link) { _cleanup_route_free_ Route *route = NULL; _cleanup_route_free_ Route *route_gw = NULL; - r = sd_dhcp_lease_get_address(link->dhcp_lease, &address); - if (r < 0) - return log_link_warning_errno(link, r, "DHCP error: could not get address: %m"); - r = route_new(&route); if (r < 0) return log_link_error_errno(link, r, "Could not allocate route: %m"); |