]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-oauth2: Fix asynchronous parsing of JSON response payload.
authorStephan Bosch <stephan.bosch@dovecot.fi>
Sun, 9 Dec 2018 20:08:53 +0000 (21:08 +0100)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Thu, 21 Mar 2019 08:03:02 +0000 (10:03 +0200)
The problem was caused by the fact that req->field_name was reset in the
beginning of oauth2_parse_json(), which is continuously called when more payload
can be read from the input stream. This leads to corruption of the parser state
machine each time parsing is continued.

To fix this issue, the field_name is now reset only when the parsing commences.

src/lib-oauth2/oauth2-introspect.c
src/lib-oauth2/oauth2-refresh.c
src/lib-oauth2/oauth2-token-validate.c
src/lib-oauth2/oauth2.c

index 9a2784e0f2c98bc8b55a36914bc6c928bf2997cd..023bb5af4e0179458477bad98fa4476e36c555e3 100644 (file)
@@ -53,6 +53,7 @@ oauth2_introspect_response(const struct http_response *response,
                req->parser = json_parser_init(req->is);
                req->json_parsed_cb = oauth2_introspect_continue;
                req->io = io_add_istream(req->is, oauth2_parse_json, req);
+               req->field_name = NULL;
                oauth2_parse_json(req);
        }
 }
index 12336527161263a0db189334e2d379a41ca16a13..2c6b720ea2eed3b5de1d7249f89dd339d99a478b 100644 (file)
@@ -93,6 +93,7 @@ oauth2_refresh_response(const struct http_response *response,
                req->parser = json_parser_init(req->is);
                req->json_parsed_cb = oauth2_refresh_continue;
                req->io = io_add_istream(req->is, oauth2_parse_json, req);
+               req->field_name = NULL;
                oauth2_parse_json(req);
        }
 }
index ca6b1c37e1a1a4c146279e746faeb547aeeb562e..17d977dc34d4f8f698de0c32cba65cfdf639841a 100644 (file)
@@ -82,6 +82,7 @@ oauth2_token_validate_response(const struct http_response *response,
                req->parser = json_parser_init(req->is);
                req->json_parsed_cb = oauth2_token_validate_continue;
                req->io = io_add_istream(req->is, oauth2_parse_json, req);
+               req->field_name = NULL;
                oauth2_parse_json(req);
        }
 }
index b63686de2396324f303a67e893f5e7e99abaa51e..a5080b97a55f637bb5df0bd61c86d6f4152c7d72 100644 (file)
@@ -17,8 +17,6 @@ oauth2_parse_json(struct oauth2_request *req)
        const char *token, *error;
        int ret;
 
-       req->field_name = NULL;
-
        while((ret = json_parse_next(req->parser, &type, &token)) > 0) {
                if (req->field_name == NULL) {
                        if (type != JSON_TYPE_OBJECT_KEY) break;