]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-oauth2: Don't fail if oauth response payload is NULL
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 26 May 2020 21:27:15 +0000 (00:27 +0300)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Mon, 7 Dec 2020 08:59:28 +0000 (08:59 +0000)
oauth2_parse_json() is happy with with empty payload (Content-Length: 0),
so it should be happy also when payload is NULL (Content-Length is missing).

src/lib-oauth2/oauth2-request.c

index 15bce9d7d7904af50b2fa32c71a1fab8ab2e0984..4f1a7f735839e02816c9e2a7a653af608a77a48c 100644 (file)
@@ -77,17 +77,15 @@ static void
 oauth2_request_response(const struct http_response *response,
                        struct oauth2_request *req)
 {
-       if (response->payload == NULL) {
-               struct oauth2_request_result res;
-               i_zero(&res);
-               res.error = http_response_get_message(response);
-               oauth2_request_callback(req, &res);
-               return;
+       if (response->payload != NULL) {
+               req->is = response->payload;
+               i_stream_ref(req->is);
+       } else {
+               req->is = i_stream_create_from_data("", 0);
        }
+
        req->response_status = response->status;
        p_array_init(&req->fields, req->pool, 1);
-       req->is = response->payload;
-       i_stream_ref(req->is);
        req->parser = json_parser_init(req->is);
        req->json_parsed_cb = oauth2_request_continue;
        req->io = io_add_istream(req->is, oauth2_parse_json, req);