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; 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