diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2020-09-03 10:05:12 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2020-09-10 00:46:44 +0200 |
commit | 25b2d602b91a5b9225e3f7c72d77e51face237ad (patch) | |
tree | dd868f112a7c74abf8dfac0b064be645f7ba6643 /src/shared/socket-netlink.c | |
parent | 610618ff61a87ae652116d2e0b58fa556b3c66ba (diff) | |
download | systemd-25b2d602b91a5b9225e3f7c72d77e51face237ad.tar.gz |
shared/socket-netlink: only allow ifindex if explicitly supported
Instead of ignoring ifindex if not wanted, refuse it is the caller
does not allow it.
Diffstat (limited to 'src/shared/socket-netlink.c')
-rw-r--r-- | src/shared/socket-netlink.c | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/src/shared/socket-netlink.c b/src/shared/socket-netlink.c index 6c121a4c9a..4b52fa3097 100644 --- a/src/shared/socket-netlink.c +++ b/src/shared/socket-netlink.c @@ -345,10 +345,14 @@ int in_addr_port_ifindex_name_from_string_auto( /* This accepts the following: * 192.168.0.1:53#example.com - * [2001:4860:4860::8888]:53%eth0#example.com */ - - /* if ret_port is NULL, then strings with port cannot be specified. - * Also, if ret_server_name is NULL, then server_name cannot be specified. */ + * [2001:4860:4860::8888]:53%eth0#example.com + * + * If ret_port is NULL, then the port cannot be specified. + * If ret_ifindex is NULL, then the interface index cannot be specified. + * If ret_server_name is NULL, then server_name cannot be specified. + * + * ret_family is always AF_INET or AF_INET6. + */ m = strchr(s, '#'); if (m) { @@ -369,15 +373,15 @@ int in_addr_port_ifindex_name_from_string_auto( m = strchr(s, '%'); if (m) { + if (!ret_ifindex) + return -EINVAL; + if (isempty(m + 1)) return -EINVAL; - if (ret_ifindex) { - /* If we shall return the interface index, try to parse it */ - ifindex = resolve_interface(NULL, m + 1); - if (ifindex < 0) - return ifindex; - } + ifindex = resolve_interface(NULL, m + 1); + if (ifindex < 0) + return ifindex; s = buf2 = strndup(s, m - s); if (!buf2) |