diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2021-06-23 15:57:28 +0900 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2021-06-23 15:59:44 +0900 |
commit | 5a3586db9a7e455fc54f9aa19652b48edbae3dd9 (patch) | |
tree | ff9dc77fc3862fb607a74c199e13be4082596e99 /src/basic/socket-util.c | |
parent | abfbfee36cc3a13f52e662e98338971dcbf3a87d (diff) | |
download | systemd-5a3586db9a7e455fc54f9aa19652b48edbae3dd9.tar.gz |
socket-util: split out checking valid character for ifname into ifname_valid_char()
Diffstat (limited to 'src/basic/socket-util.c')
-rw-r--r-- | src/basic/socket-util.c | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/src/basic/socket-util.c b/src/basic/socket-util.c index f6e751a09f..1c353e86b0 100644 --- a/src/basic/socket-util.c +++ b/src/basic/socket-util.c @@ -748,6 +748,22 @@ static const char* const ip_tos_table[] = { DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(ip_tos, int, 0xff); +bool ifname_valid_char(char a) { + if ((unsigned char) a >= 127U) + return false; + + if ((unsigned char) a <= 32U) + return false; + + if (IN_SET(a, + ':', /* colons are used by the legacy "alias" interface logic */ + '/', /* slashes cannot work, since we need to use network interfaces in sysfs paths, and in paths slashes are separators */ + '%')) /* %d is used in the kernel's weird foo%d format string naming feature which we really really don't want to ever run into by accident */ + return false; + + return true; +} + bool ifname_valid_full(const char *p, IfnameValidFlags flags) { bool numeric = true; @@ -781,16 +797,7 @@ bool ifname_valid_full(const char *p, IfnameValidFlags flags) { return false; for (const char *t = p; *t; t++) { - if ((unsigned char) *t >= 127U) - return false; - - if ((unsigned char) *t <= 32U) - return false; - - if (IN_SET(*t, - ':', /* colons are used by the legacy "alias" interface logic */ - '/', /* slashes cannot work, since we need to use network interfaces in sysfs paths, and in paths slashes are separators */ - '%')) /* %d is used in the kernel's weird foo%d format string naming feature which we really really don't want to ever run into by accident */ + if (!ifname_valid_char(*t)) return false; numeric = numeric && (*t >= '0' && *t <= '9'); |