liblog: tests: crashes in logcat.descriptive
scanTagLine has some loops that do not check for a terminating nul,
problematic for responses from the logger via __getEventTag.
Test: gTest logcat-unit-tests --gtest_filter=*.descriptive
Bug: 37791296
Change-Id: Ib4e900b765b407bdee43e009d6625fe289863ddc
diff --git a/liblog/event_tag_map.cpp b/liblog/event_tag_map.cpp
index 5fc7e35..83064fd 100644
--- a/liblog/event_tag_map.cpp
+++ b/liblog/event_tag_map.cpp
@@ -297,9 +297,9 @@
while (isspace(*cp) && (*cp != '\n')) ++cp;
const char* fmt = NULL;
size_t fmtLen = 0;
- if (*cp != '#') {
+ if (*cp && (*cp != '#')) {
fmt = cp;
- while ((*cp != '\n') && (*cp != '#')) ++cp;
+ while (*cp && (*cp != '\n') && (*cp != '#')) ++cp;
while ((cp > fmt) && isspace(*(cp - 1))) --cp;
fmtLen = cp - fmt;
}
@@ -309,7 +309,7 @@
// recorded for the same uid, but recording that
// unused detail in our database is too burdensome.
bool verbose = true;
- while ((*cp != '#') && (*cp != '\n')) ++cp;
+ while (*cp && (*cp != '#') && (*cp != '\n')) ++cp;
if (*cp == '#') {
do {
++cp;
@@ -317,7 +317,7 @@
verbose = !!fastcmp<strncmp>(cp, "uid=", strlen("uid="));
}
- while (*cp != '\n') ++cp;
+ while (*cp && (*cp != '\n')) ++cp;
#ifdef DEBUG
fprintf(stderr, "%d: %p: %.*s\n", lineNum, tag, (int)(cp - pData), pData);
#endif