diff options
author | Susant Sahani <susant@redhat.com> | 2017-02-28 16:53:58 +0530 |
---|---|---|
committer | Susant Sahani <susant@redhat.com> | 2017-02-28 16:53:58 +0530 |
commit | 2680894816b49b9e55f0a42a420d0540892e9b61 (patch) | |
tree | 8eceadd279594adddcd93c733825cc54dbce732b | |
parent | ccdda9556ee67a6b1c12e2a33cc309ad8fb06996 (diff) |
socket-util: introduce address_label_valid
-rw-r--r-- | src/basic/socket-util.c | 20 | ||||
-rw-r--r-- | src/basic/socket-util.h | 1 |
2 files changed, 21 insertions, 0 deletions
diff --git a/src/basic/socket-util.c b/src/basic/socket-util.c index 17e90a8994..e5847dce00 100644 --- a/src/basic/socket-util.c +++ b/src/basic/socket-util.c @@ -900,6 +900,26 @@ bool ifname_valid(const char *p) { return true; } +bool address_label_valid(const char *p) { + + if (isempty(p)) + return false; + + if (strlen(p) >= IFNAMSIZ) + return false; + + while (*p) { + if ((uint8_t) *p >= 127U) + return false; + + if ((uint8_t) *p <= 31U) + return false; + p++; + } + + return true; +} + int getpeercred(int fd, struct ucred *ucred) { socklen_t n = sizeof(struct ucred); struct ucred u; diff --git a/src/basic/socket-util.h b/src/basic/socket-util.h index 3c42e220e5..73c3a339fc 100644 --- a/src/basic/socket-util.h +++ b/src/basic/socket-util.h @@ -126,6 +126,7 @@ int ip_tos_to_string_alloc(int i, char **s); int ip_tos_from_string(const char *s); bool ifname_valid(const char *p); +bool address_label_valid(const char *p); int getpeercred(int fd, struct ucred *ucred); int getpeersec(int fd, char **ret); |