summaryrefslogtreecommitdiff
path: root/src/basic/socket-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2021-02-15 22:49:36 +0100
committerLennart Poettering <lennart@poettering.net>2021-02-15 22:51:16 +0100
commitee29bd5dc5b08427a919ff84eeb06ee4158a3ae2 (patch)
tree20b12a609dcccc310bb8b927e64a5408801a3e65 /src/basic/socket-util.c
parente774e6fb0420e7b441aedbe0d013bb51aa7b5337 (diff)
downloadsystemd-ee29bd5dc5b08427a919ff84eeb06ee4158a3ae2.tar.gz
socket-util: tighten parsing of ifnames
Numeric ifnames should be acceptable only if that's enabled by flag, and refused otherwise. Hence, let's parse as ifindex first, and if that works decide. Finally, let's refuse any numeric ifnames that are not valid ifindexs, but look like them.
Diffstat (limited to 'src/basic/socket-util.c')
-rw-r--r--src/basic/socket-util.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/basic/socket-util.c b/src/basic/socket-util.c
index 59039bea4f..8267988ad9 100644
--- a/src/basic/socket-util.c
+++ b/src/basic/socket-util.c
@@ -721,6 +721,10 @@ bool ifname_valid_full(const char *p, IfnameValidFlags flags) {
if (isempty(p))
return false;
+ /* A valid ifindex? If so, it's valid iff IFNAME_VALID_NUMERIC is set */
+ if (parse_ifindex(p) >= 0)
+ return flags & IFNAME_VALID_NUMERIC;
+
if (flags & IFNAME_VALID_ALTERNATIVE) {
if (strlen(p) >= ALTIFNAMSIZ)
return false;
@@ -745,14 +749,10 @@ bool ifname_valid_full(const char *p, IfnameValidFlags flags) {
numeric = numeric && (*t >= '0' && *t <= '9');
}
- if (numeric) {
- if (!(flags & IFNAME_VALID_NUMERIC))
- return false;
-
- /* Verify that the number is well-formatted and in range. */
- if (parse_ifindex(p) < 0)
- return false;
- }
+ /* It's fully numeric but didn't parse as valid ifindex above? if so, it must be too large or zero or
+ * so, let's refuse that. */
+ if (numeric)
+ return false;
return true;
}