From: Scott Griepentrog Date: Tue, 18 Mar 2014 15:45:04 +0000 (+0000) Subject: ARI: allow json content type with zero length body X-Git-Tag: 13.0.0-beta1~424 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eecb74a9a730a87bcbbe0cba5b961e7e457d0968;p=thirdparty%2Fasterisk.git ARI: allow json content type with zero length body When a request was received with a Content-type of json, the body was sent for json parsing - even if it was zero length. This resulted in ARI requests failing that were valid, such as a channel DELETE with no parameters. The code has now been changed to skip json parsing with zero content length. (closes issue SWP-6748) Reported by: Samuel Galarneau Review: https://reviewboard.asterisk.org/r/3360/ ........ Merged revisions 410858 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@410863 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- diff --git a/main/http.c b/main/http.c index 0e45b60db6..e2982a73b5 100644 --- a/main/http.c +++ b/main/http.c @@ -880,12 +880,16 @@ struct ast_json *ast_http_get_json( } buf = ast_http_get_contents(&content_length, ser, headers); - if (buf == NULL) - { + if (buf == NULL) { /* errno already set */ return NULL; } + if (!content_length) { + /* it is not an error to have zero content */ + return NULL; + } + body = ast_json_load_buf(buf, content_length, NULL); if (body == NULL) { /* Failed to parse JSON; treat as an I/O error */