From 954f00f5fbef9cc6e3985421d02565d84d87569c Mon Sep 17 00:00:00 2001 From: onefang Date: Mon, 13 Jun 2022 11:35:00 +1000 Subject: Less crashy teapots. --- src/sledjchisl/sledjchisl.c | 54 +++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/src/sledjchisl/sledjchisl.c b/src/sledjchisl/sledjchisl.c index 0710063..cddb167 100644 --- a/src/sledjchisl/sledjchisl.c +++ b/src/sledjchisl/sledjchisl.c @@ -9619,40 +9619,42 @@ t("BODY"); Body = xmalloc(1); Body[0] = '\0'; } - if (strcmp("application/json", type) == 0) + if (NULL != type) { - json_char *json = (json_char*) Body; - json_value* value = json_parse(json, strtol(Length, NULL, 10)); - - Rd->body = qhashtbl(0, 0); - if (value == NULL) - E("Unable to parse NULL data!"); - else + if (strcmp("application/json", type) == 0) { -// PrintJSON(json); - if (value->type == json_object) - { - int length = value->u.object.length, x; + json_char *json = (json_char*) Body; + json_value* value = json_parse(json, strtol(Length, NULL, 10)); - for (x = 0; x < length; x++) + Rd->body = qhashtbl(0, 0); + if (value == NULL) + E("Unable to parse NULL data!"); + else + { +// PrintJSON(json); + if (value->type == json_object) { - char *name = value->u.object.values[x].name; + int length = value->u.object.length, x; - if (value->u.object.values[x].value->type == json_string) - { - D("%s = %s", name, value->u.object.values[x].value->u.string.ptr); - Rd->body->putstr(Rd->body, name, value->u.object.values[x].value->u.string.ptr); - } - + for (x = 0; x < length; x++) + { + char *name = value->u.object.values[x].name; + + if (value->u.object.values[x].value->type == json_string) + { + D("%s = %s", name, value->u.object.values[x].value->u.string.ptr); + Rd->body->putstr(Rd->body, name, value->u.object.values[x].value->u.string.ptr); + } + } } } + json_value_free(value); + } + else + { + Rd->body = toknize(Body, "=&"); + santize(Rd->body); } - json_value_free(value); - } - else - { - Rd->body = toknize(Body, "=&"); - santize(Rd->body); } free(Body); -- cgit v1.1