X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Flibsystemd-bus%2Fbus-signature.c;h=1e5bf4821d9526da05478c92cfe2785acd611b08;hb=7fb411f035e68b5f3f5e2893157739c9da9917b0;hp=db95c8870de2ba04406f7776922943ff89e5116b;hpb=de1c301ed165eb4d04a0c9d4babe97912b5233bb;p=elogind.git diff --git a/src/libsystemd-bus/bus-signature.c b/src/libsystemd-bus/bus-signature.c index db95c8870..1e5bf4821 100644 --- a/src/libsystemd-bus/bus-signature.c +++ b/src/libsystemd-bus/bus-signature.c @@ -27,11 +27,16 @@ static int signature_element_length_internal( const char *s, bool allow_dict_entry, + unsigned array_depth, + unsigned struct_depth, size_t *l) { int r; - assert(s); + if (!s) + return -EINVAL; + + assert(l); if (bus_type_is_basic(*s) || *s == SD_BUS_TYPE_VARIANT) { *l = 1; @@ -41,7 +46,10 @@ static int signature_element_length_internal( if (*s == SD_BUS_TYPE_ARRAY) { size_t t; - r = signature_element_length_internal(s + 1, true, &t); + if (array_depth >= 32) + return -EINVAL; + + r = signature_element_length_internal(s + 1, true, array_depth+1, struct_depth, &t); if (r < 0) return r; @@ -52,10 +60,13 @@ static int signature_element_length_internal( if (*s == SD_BUS_TYPE_STRUCT_BEGIN) { const char *p = s + 1; + if (struct_depth >= 32) + return -EINVAL; + while (*p != SD_BUS_TYPE_STRUCT_END) { size_t t; - r = signature_element_length_internal(p, false, &t); + r = signature_element_length_internal(p, false, array_depth, struct_depth+1, &t); if (r < 0) return r; @@ -70,13 +81,16 @@ static int signature_element_length_internal( const char *p = s + 1; unsigned n = 0; + if (struct_depth >= 32) + return -EINVAL; + while (*p != SD_BUS_TYPE_DICT_ENTRY_END) { size_t t; if (n == 0 && !bus_type_is_basic(*p)) return -EINVAL; - r = signature_element_length_internal(p, false, &t); + r = signature_element_length_internal(p, false, array_depth, struct_depth+1, &t); if (r < 0) return r; @@ -94,13 +108,19 @@ static int signature_element_length_internal( return -EINVAL; } -bool signature_is_single(const char *s) { + +int signature_element_length(const char *s, size_t *l) { + return signature_element_length_internal(s, true, 0, 0, l); +} + +bool signature_is_single(const char *s, bool allow_dict_entry) { int r; size_t t; - assert(s); + if (!s) + return false; - r = signature_element_length(s, &t); + r = signature_element_length_internal(s, allow_dict_entry, 0, 0, &t); if (r < 0) return false; @@ -108,25 +128,28 @@ bool signature_is_single(const char *s) { } bool signature_is_pair(const char *s) { - assert(s); + + if (!s) + return false; if (!bus_type_is_basic(*s)) return false; - return signature_is_single(s + 1); + return signature_is_single(s + 1, false); } bool signature_is_valid(const char *s, bool allow_dict_entry) { const char *p; int r; - assert(s); + if (!s) + return false; p = s; while (*p) { size_t t; - r = signature_element_length_internal(p, allow_dict_entry, &t); + r = signature_element_length_internal(p, allow_dict_entry, 0, 0, &t); if (r < 0) return false; @@ -135,7 +158,3 @@ bool signature_is_valid(const char *s, bool allow_dict_entry) { return p - s <= 255; } - -int signature_element_length(const char *s, size_t *l) { - return signature_element_length_internal(s, true, l); -}