From 21a925a4ac7955e7d7e6cfd477e96d3a2aaee7db Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 12 Dec 2019 19:01:21 +0900 Subject: [PATCH 1/2] network-generator: allow empty hostname Fixes #14319. --- src/network/generator/network-generator.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/network/generator/network-generator.c b/src/network/generator/network-generator.c index 81afa95307..bed1e42697 100644 --- a/src/network/generator/network-generator.c +++ b/src/network/generator/network-generator.c @@ -574,7 +574,7 @@ static int parse_netmask_or_prefixlen(int family, const char **value, unsigned c static int parse_cmdline_ip_address(Context *context, int family, const char *value) { union in_addr_union addr = {}, peer = {}, gateway = {}; - const char *hostname, *ifname, *dhcp_type, *dns, *p; + const char *hostname = NULL, *ifname, *dhcp_type, *dns, *p; unsigned char prefixlen; int r; @@ -599,9 +599,11 @@ static int parse_cmdline_ip_address(Context *context, int family, const char *va if (!p) return -EINVAL; - hostname = strndupa(value, p - value); - if (!hostname_is_valid(hostname, false)) - return -EINVAL; + if (p != value) { + hostname = strndupa(value, p - value); + if (!hostname_is_valid(hostname, false)) + return -EINVAL; + } value = p + 1; From dd1e09971b7d2d699e660fe7f714d3d9a361afbf Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 12 Dec 2019 19:02:25 +0900 Subject: [PATCH 2/2] test: add a test case for network-generator --- .../90-enp3s0.network | 17 +++++++++++++++++ .../test-03-issue-14319.input | 1 + 2 files changed, 18 insertions(+) create mode 100644 test/TEST-35-NETWORK-GENERATOR/test-03-issue-14319.expected/90-enp3s0.network create mode 100644 test/TEST-35-NETWORK-GENERATOR/test-03-issue-14319.input diff --git a/test/TEST-35-NETWORK-GENERATOR/test-03-issue-14319.expected/90-enp3s0.network b/test/TEST-35-NETWORK-GENERATOR/test-03-issue-14319.expected/90-enp3s0.network new file mode 100644 index 0000000000..28ccfdd9b0 --- /dev/null +++ b/test/TEST-35-NETWORK-GENERATOR/test-03-issue-14319.expected/90-enp3s0.network @@ -0,0 +1,17 @@ +# Automatically generated by systemd-network-generator + +[Match] +Name=enp3s0 + +[Link] + +[Network] +DHCP=no + +[DHCP] + +[Address] +Address=10.99.37.44/16 + +[Route] +Gateway=10.99.10.1 diff --git a/test/TEST-35-NETWORK-GENERATOR/test-03-issue-14319.input b/test/TEST-35-NETWORK-GENERATOR/test-03-issue-14319.input new file mode 100644 index 0000000000..3be752067b --- /dev/null +++ b/test/TEST-35-NETWORK-GENERATOR/test-03-issue-14319.input @@ -0,0 +1 @@ +root=/dev/nfs nfsroot=10.99.37.240:/srv/netroot,v3,tcp ip=10.99.37.44::10.99.10.1:255.255.0.0::enp3s0:off