From: Susant Sahani Date: Tue, 28 Feb 2017 11:23:58 +0000 (+0530) Subject: socket-util: introduce address_label_valid X-Git-Tag: v233.3~31 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=commitdiff_plain;h=eeb58b12cdce99bcbc654a9b89f9e7622ad3eb04 socket-util: introduce address_label_valid --- diff --git a/src/basic/socket-util.c b/src/basic/socket-util.c index 9ec901261..68773d54c 100644 --- a/src/basic/socket-util.c +++ b/src/basic/socket-util.c @@ -904,6 +904,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 195bfb830..8e18eed8c 100644 --- a/src/basic/socket-util.h +++ b/src/basic/socket-util.h @@ -131,6 +131,7 @@ int ip_tos_from_string(const char *s); #endif // 0 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);