summaryrefslogtreecommitdiff
path: root/libs/protoutil/src
diff options
context:
space:
mode:
authorYi Jin <jinyithu@google.com>2018-04-27 11:51:13 -0700
committerYi Jin <jinyithu@google.com>2018-04-27 14:16:50 -0700
commit18678bdca07a30d30676bc931bfea2b697607f8b (patch)
treedec59bac25f697ff0a388238541429dc4ae9d408 /libs/protoutil/src
parent50817a4c5481124eda4c74ec6ce6c7f33f3cf7d2 (diff)
Empty output if compact fails.
There must be equal number of start/end calls with right token given in order, if used in wrong order, ProtoOutputStream will have empty output. Also refactor Android.bp, so the gtest is standalone unit test, it used to require compile/push libprotoutil.so to device. Bug: 77342154 Test: atest libprotoutil_test Change-Id: I0011bbab34c04cb38164d2ed21cd818d52a2ecf9
Diffstat (limited to 'libs/protoutil/src')
-rw-r--r--libs/protoutil/src/ProtoOutputStream.cpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/libs/protoutil/src/ProtoOutputStream.cpp b/libs/protoutil/src/ProtoOutputStream.cpp
index 0d429e0ba6c8..ff3fad6055e1 100644
--- a/libs/protoutil/src/ProtoOutputStream.cpp
+++ b/libs/protoutil/src/ProtoOutputStream.cpp
@@ -244,12 +244,14 @@ ProtoOutputStream::end(uint64_t token)
{
if (token != mExpectedObjectToken) {
ALOGE("Unexpected token: 0x%" PRIx64 ", should be 0x%" PRIx64, token, mExpectedObjectToken);
+ mDepth = UINT32_C(-1); // make depth invalid
return;
}
uint32_t depth = getDepthFromToken(token);
if (depth != (mDepth & 0x01ff)) {
ALOGE("Unexpected depth: %" PRIu32 ", should be %" PRIu32, depth, mDepth);
+ mDepth = UINT32_C(-1); // make depth invalid
return;
}
mDepth--;
@@ -282,7 +284,7 @@ bool
ProtoOutputStream::compact() {
if (mCompact) return true;
if (mDepth != 0) {
- ALOGE("Can't compact when depth(%" PRIu32 ") is not zero. Missing calls to end.", mDepth);
+ ALOGE("Can't compact when depth(%" PRIu32 ") is not zero. Missing or extra calls to end.", mDepth);
return false;
}
// record the size of the original buffer.
@@ -425,7 +427,7 @@ ProtoOutputStream::size()
{
if (!compact()) {
ALOGE("compact failed, the ProtoOutputStream data is corrupted!");
- // TODO: handle this error
+ return 0;
}
return mBuffer.size();
}
@@ -449,7 +451,7 @@ ProtoOutputStream::data()
{
if (!compact()) {
ALOGE("compact failed, the ProtoOutputStream data is corrupted!");
- // TODO: handle this error
+ mBuffer.clear();
}
return mBuffer.begin();
}