diff options
author | Lennart Poettering <lennart@poettering.net> | 2013-03-22 00:42:53 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2013-03-22 00:42:53 +0100 |
commit | ac89bf1d53268d39025a2a00c2effdb3fa447ead (patch) | |
tree | 8a1ed549ab3b4938d3d2c296cd66b5c57fd4fc03 /src/libsystemd-bus/bus-internal.c | |
parent | b8beb2781682738f3a59aab993bf2869447a77c9 (diff) |
bus: properly validate object path values
Diffstat (limited to 'src/libsystemd-bus/bus-internal.c')
-rw-r--r-- | src/libsystemd-bus/bus-internal.c | 40 |
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; +} |