shared: check interface name validity in in_addr_port_ifindex_name_from_string_auto()

We don't try to resolve invalid ifnames as all. A different return
code is used. This difference will be verified later in test_socket_address_parse()
when socket_address_parse() is converted to use
in_addr_port_ifindex_name_from_string_auto().
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2020-09-03 15:38:46 +02:00
parent b16d17a68a
commit c1f848d73c
1 changed files with 4 additions and 0 deletions

View File

@ -379,6 +379,10 @@ int in_addr_port_ifindex_name_from_string_auto(
if (isempty(m + 1))
return -EINVAL;
if (!ifname_valid_full(m + 1, IFNAME_VALID_ALTERNATIVE | IFNAME_VALID_NUMERIC))
return -EINVAL; /* We want to return -EINVAL for syntactically invalid names,
* and -ENODEV for valid but nonexistent interfaces. */
ifindex = resolve_interface(NULL, m + 1);
if (ifindex < 0)
return ifindex;