summaryrefslogtreecommitdiff
path: root/src/basic/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/basic/util.c')
-rw-r--r--src/basic/util.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/basic/util.c b/src/basic/util.c
index c63ec0ceb0..054d45092e 100644
--- a/src/basic/util.c
+++ b/src/basic/util.c
@@ -6842,3 +6842,28 @@ int version(void) {
SYSTEMD_FEATURES);
return 0;
}
+
+bool fdname_is_valid(const char *s) {
+ const char *p;
+
+ /* Validates a name for $LISTEN_NAMES. We basically allow
+ * everything ASCII that's not a control character. Also, as
+ * special exception the ":" character is not allowed, as we
+ * use that as field separator in $LISTEN_NAMES.
+ *
+ * Note that the empty string is explicitly allowed here.*/
+
+ if (!s)
+ return false;
+
+ for (p = s; *p; p++) {
+ if (*p < ' ')
+ return false;
+ if (*p >= 127)
+ return false;
+ if (*p == ':')
+ return false;
+ }
+
+ return p - s < 256;
+}