Skip to content

Fix crash caused by ResponseJson::MarkCompleted() failing to set application_data_ if parsing the JSON body fails #692

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions app/rest/response_json.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "app/rest/response.h"
#include "app/src/assert.h"
#include "app/src/log.h"
#include "flatbuffers/idl.h"
#include "flatbuffers/stl_emulation.h"

Expand Down Expand Up @@ -74,12 +75,24 @@ class ResponseJson : public Response {
// Parse and verify JSON string in body. FlatBuffer parser does not support
// online parsing. So we only parse the body when we get everything.
bool parse_status = parser_->Parse(GetBody());
FIREBASE_ASSERT_RETURN_VOID(parse_status);
if (!parse_status) {
LogError("flatbuffers::Parser::Parse() failed: %s",
parser_->error_.c_str());
application_data_.reset(new FbsTypeT());
Response::MarkCompleted();
return;
}

const flatbuffers::FlatBufferBuilder& builder = parser_->builder_;
flatbuffers::Verifier verifier(builder.GetBufferPointer(),
builder.GetSize());
bool verify_status = verifier.VerifyBuffer<FbsType>(nullptr);
FIREBASE_ASSERT_RETURN_VOID(verify_status);
if (!verify_status) {
LogError("flatbuffers::Verifier::VerifyBuffer() failed");
application_data_.reset(new FbsTypeT());
Response::MarkCompleted();
return;
}

// UnPack application data object from FlatBuffer.
const FbsType* body_fbs =
Expand Down
3 changes: 3 additions & 0 deletions release_build_files/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,9 @@ code.
- Messaging (Android): Fixes an issue to receive token when
initialize the app.
([#667](https://github.com/firebase/firebase-cpp-sdk/pull/667)).
- Auth (Desktop): Fix a crash that would occur if parsing the JSON
response from the server failed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: period.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The period occurs after the PR link on line 581.

([#692](https://github.com/firebase/firebase-cpp-sdk/pull/692)).

### 8.5.0
- Changes
Expand Down