From b97fd69aae5c145bf3d390a9a6d3783eb9584aa5 Mon Sep 17 00:00:00 2001 From: Mina Farid Date: Mon, 18 Jun 2018 11:53:30 -0400 Subject: Avoid closing unintialized substreams (#1411) * A substream should not be closed if pb_make_string_substream() failed to create it and returned false. * Fixed a potential wrong error message. --- Firestore/core/src/firebase/firestore/nanopb/reader.cc | 3 +-- Firestore/core/src/firebase/firestore/nanopb/reader.h | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) (limited to 'Firestore/core/src/firebase') diff --git a/Firestore/core/src/firebase/firestore/nanopb/reader.cc b/Firestore/core/src/firebase/firestore/nanopb/reader.cc index 69e3d83..3b102f0 100644 --- a/Firestore/core/src/firebase/firestore/nanopb/reader.cc +++ b/Firestore/core/src/firebase/firestore/nanopb/reader.cc @@ -110,14 +110,13 @@ std::string Reader::ReadString() { pb_istream_t substream; if (!pb_make_string_substream(&stream_, &substream)) { status_ = Status(FirestoreErrorCode::DataLoss, PB_GET_ERROR(&stream_)); - pb_close_string_substream(&stream_, &substream); return ""; } std::string result(substream.bytes_left, '\0'); if (!pb_read(&substream, reinterpret_cast(&result[0]), substream.bytes_left)) { - status_ = Status(FirestoreErrorCode::DataLoss, PB_GET_ERROR(&stream_)); + status_ = Status(FirestoreErrorCode::DataLoss, PB_GET_ERROR(&substream)); pb_close_string_substream(&stream_, &substream); return ""; } diff --git a/Firestore/core/src/firebase/firestore/nanopb/reader.h b/Firestore/core/src/firebase/firestore/nanopb/reader.h index 2c16ec4..7dd7432 100644 --- a/Firestore/core/src/firebase/firestore/nanopb/reader.h +++ b/Firestore/core/src/firebase/firestore/nanopb/reader.h @@ -150,7 +150,6 @@ T Reader::ReadNestedMessage(const std::function& read_message_fn) { if (!pb_make_string_substream(&stream_, &raw_substream)) { status_ = util::Status(FirestoreErrorCode::DataLoss, PB_GET_ERROR(&stream_)); - pb_close_string_substream(&stream_, &raw_substream); return read_message_fn(this); } Reader substream(raw_substream); -- cgit v1.2.3