Skip to content

Commit

Permalink
lib-oauth2: Fix asynchronous parsing of JSON response payload.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
stephanbosch authored and sirainen committed Mar 4, 2019
1 parent dbc7e7a commit c68a0ef
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/lib-oauth2/oauth2-introspect.c
Expand Up @@ -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);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/lib-oauth2/oauth2-refresh.c
Expand Up @@ -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);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/lib-oauth2/oauth2-token-validate.c
Expand Up @@ -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);
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/lib-oauth2/oauth2.c
Expand Up @@ -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;
Expand Down

0 comments on commit c68a0ef

Please sign in to comment.