1
0
mirror of https://github.com/systemd/systemd.git synced 2025-02-10 17:57:40 +03:00

Merge pull request #18611 from poettering/ifname-validate-tighter

make ifname validation tighter
This commit is contained in:
Lennart Poettering 2021-02-16 09:52:32 +01:00 committed by GitHub
commit 0e703bb48d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 11 deletions

View File

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

View File

@ -133,9 +133,9 @@ int ip_tos_to_string_alloc(int i, char **s);
int ip_tos_from_string(const char *s);
typedef enum {
IFNAME_VALID_ALTERNATIVE = 1 << 0,
IFNAME_VALID_NUMERIC = 1 << 1,
_IFNAME_VALID_ALL = IFNAME_VALID_ALTERNATIVE | IFNAME_VALID_NUMERIC,
IFNAME_VALID_ALTERNATIVE = 1 << 0,
IFNAME_VALID_NUMERIC = 1 << 1,
_IFNAME_VALID_ALL = IFNAME_VALID_ALTERNATIVE | IFNAME_VALID_NUMERIC,
} IfnameValidFlags;
bool ifname_valid_full(const char *p, IfnameValidFlags flags);
static inline bool ifname_valid(const char *p) {