chiark / gitweb /
socket-util: introduce address_label_valid
authorSusant Sahani <susant@redhat.com>
Tue, 28 Feb 2017 11:23:58 +0000 (16:53 +0530)
committerSven Eden <yamakuzure@gmx.net>
Mon, 17 Jul 2017 15:58:36 +0000 (17:58 +0200)
src/basic/socket-util.c
src/basic/socket-util.h

index 9ec9012611c6346141bc276599548702042b6e0c..68773d54cc2f389f5ef3e11dc1022783898e0252 100644 (file)
@@ -904,6 +904,26 @@ bool ifname_valid(const char *p) {
         return true;
 }
 
         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;
 int getpeercred(int fd, struct ucred *ucred) {
         socklen_t n = sizeof(struct ucred);
         struct ucred u;
index 195bfb8300ad209df018affb72ce65c661392e69..8e18eed8cc6297a2098ce85642ef323be2b6fcbc 100644 (file)
@@ -131,6 +131,7 @@ int ip_tos_from_string(const char *s);
 #endif // 0
 
 bool ifname_valid(const char *p);
 #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);
 
 int getpeercred(int fd, struct ucred *ucred);
 int getpeersec(int fd, char **ret);