summaryrefslogtreecommitdiff
path: root/src/libsystemd-bus/bus-internal.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-03-22 00:42:53 +0100
committerLennart Poettering <lennart@poettering.net>2013-03-22 00:42:53 +0100
commitac89bf1d53268d39025a2a00c2effdb3fa447ead (patch)
tree8a1ed549ab3b4938d3d2c296cd66b5c57fd4fc03 /src/libsystemd-bus/bus-internal.c
parentb8beb2781682738f3a59aab993bf2869447a77c9 (diff)
bus: properly validate object path values
Diffstat (limited to 'src/libsystemd-bus/bus-internal.c')
-rw-r--r--src/libsystemd-bus/bus-internal.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/libsystemd-bus/bus-internal.c b/src/libsystemd-bus/bus-internal.c
index 19398af6cb..e58a8b1da1 100644
--- a/src/libsystemd-bus/bus-internal.c
+++ b/src/libsystemd-bus/bus-internal.c
@@ -20,3 +20,43 @@
***/
#include "bus-internal.h"
+
+bool object_path_is_valid(const char *p) {
+ const char *q;
+ bool slash;
+
+ if (!p)
+ return false;
+
+ if (p[0] != '/')
+ return false;
+
+ if (p[1] == 0)
+ return true;
+
+ for (slash = true, q = p+1; *q; q++)
+ if (*q == '/') {
+ if (slash)
+ return false;
+
+ slash = true;
+ } else {
+ bool good;
+
+ good =
+ (*q >= 'a' && *q <= 'z') ||
+ (*q >= 'A' && *q <= 'Z') ||
+ (*q >= '0' && *q <= '9') ||
+ *q == '_';
+
+ if (!good)
+ return false;
+
+ slash = false;
+ }
+
+ if (slash)
+ return false;
+
+ return true;
+}