|
Zbigniew Jędrzejewski-Szmek |
d743bb |
From 57497d1f0367e4418c7c5e419ba0f911ad840ce9 Mon Sep 17 00:00:00 2001
|
|
Zbigniew Jędrzejewski-Szmek |
d743bb |
From: Daniel Wang <wonderfly@users.noreply.github.com>
|
|
Zbigniew Jędrzejewski-Szmek |
d743bb |
Date: Wed, 24 May 2017 05:05:49 -0700
|
|
Zbigniew Jędrzejewski-Szmek |
d743bb |
Subject: [PATCH] DHCP: Fail link_dhcp_set_routes promotely if no address is
|
|
Zbigniew Jędrzejewski-Szmek |
d743bb |
assigned from lease (#6009)
|
|
Zbigniew Jędrzejewski-Szmek |
d743bb |
|
|
Zbigniew Jędrzejewski-Szmek |
d743bb |
Currently the local variable `address` is unintialized if the DHCP lease
|
|
Zbigniew Jędrzejewski-Szmek |
d743bb |
doesn't provide a router address (when r == -ENODATA). Thus the
|
|
Zbigniew Jędrzejewski-Szmek |
d743bb |
subsequent call to route_scope_from_address will result in accessing an
|
|
Zbigniew Jędrzejewski-Szmek |
d743bb |
unintialized variable.
|
|
Zbigniew Jędrzejewski-Szmek |
d743bb |
|
|
Zbigniew Jędrzejewski-Szmek |
d743bb |
As a matter of fact, sd-dhcp-client ignores DHCP leases without an
|
|
Zbigniew Jędrzejewski-Szmek |
d743bb |
address so link_dhcp_set_routes probably will never be called without a
|
|
Zbigniew Jędrzejewski-Szmek |
d743bb |
valid address.
|
|
Zbigniew Jędrzejewski-Szmek |
d743bb |
(cherry picked from commit b23aec0d6b98bc99998786506a8769e1a1ea1841)
|
|
Zbigniew Jędrzejewski-Szmek |
d743bb |
---
|
|
Zbigniew Jędrzejewski-Szmek |
d743bb |
src/network/networkd-dhcp4.c | 8 ++++----
|
|
Zbigniew Jędrzejewski-Szmek |
d743bb |
1 file changed, 4 insertions(+), 4 deletions(-)
|
|
Zbigniew Jędrzejewski-Szmek |
d743bb |
|
|
Zbigniew Jędrzejewski-Szmek |
d743bb |
diff --git a/src/network/networkd-dhcp4.c b/src/network/networkd-dhcp4.c
|
|
Zbigniew Jędrzejewski-Szmek |
d743bb |
index ae0f78daab..9229b5753c 100644
|
|
Zbigniew Jędrzejewski-Szmek |
d743bb |
--- a/src/network/networkd-dhcp4.c
|
|
Zbigniew Jędrzejewski-Szmek |
d743bb |
+++ b/src/network/networkd-dhcp4.c
|
|
Zbigniew Jędrzejewski-Szmek |
d743bb |
@@ -77,6 +77,10 @@ static int link_set_dhcp_routes(Link *link) {
|
|
Zbigniew Jędrzejewski-Szmek |
d743bb |
if (!link->network->dhcp_use_routes)
|
|
Zbigniew Jędrzejewski-Szmek |
d743bb |
return 0;
|
|
Zbigniew Jędrzejewski-Szmek |
d743bb |
|
|
Zbigniew Jędrzejewski-Szmek |
d743bb |
+ r = sd_dhcp_lease_get_address(link->dhcp_lease, &address);
|
|
Zbigniew Jędrzejewski-Szmek |
d743bb |
+ if (r < 0)
|
|
Zbigniew Jędrzejewski-Szmek |
d743bb |
+ return log_link_warning_errno(link, r, "DHCP error: could not get address: %m");
|
|
Zbigniew Jędrzejewski-Szmek |
d743bb |
+
|
|
Zbigniew Jędrzejewski-Szmek |
d743bb |
r = sd_dhcp_lease_get_router(link->dhcp_lease, &gateway);
|
|
Zbigniew Jędrzejewski-Szmek |
d743bb |
if (r < 0 && r != -ENODATA)
|
|
Zbigniew Jędrzejewski-Szmek |
d743bb |
return log_link_warning_errno(link, r, "DHCP error: could not get gateway: %m");
|
|
Zbigniew Jędrzejewski-Szmek |
d743bb |
@@ -85,10 +89,6 @@ static int link_set_dhcp_routes(Link *link) {
|
|
Zbigniew Jędrzejewski-Szmek |
d743bb |
_cleanup_route_free_ Route *route = NULL;
|
|
Zbigniew Jędrzejewski-Szmek |
d743bb |
_cleanup_route_free_ Route *route_gw = NULL;
|
|
Zbigniew Jędrzejewski-Szmek |
d743bb |
|
|
Zbigniew Jędrzejewski-Szmek |
d743bb |
- r = sd_dhcp_lease_get_address(link->dhcp_lease, &address);
|
|
Zbigniew Jędrzejewski-Szmek |
d743bb |
- if (r < 0)
|
|
Zbigniew Jędrzejewski-Szmek |
d743bb |
- return log_link_warning_errno(link, r, "DHCP error: could not get address: %m");
|
|
Zbigniew Jędrzejewski-Szmek |
d743bb |
-
|
|
Zbigniew Jędrzejewski-Szmek |
d743bb |
r = route_new(&route);
|
|
Zbigniew Jędrzejewski-Szmek |
d743bb |
if (r < 0)
|
|
Zbigniew Jędrzejewski-Szmek |
d743bb |
return log_link_error_errno(link, r, "Could not allocate route: %m");
|