From 3eb57cc81f0382f9af9062148a79f39ec550d48d Mon Sep 17 00:00:00 2001 From: Dave Hylands Date: Tue, 18 Mar 2014 14:18:14 -0700 Subject: [PATCH] Bug 964537 - Fix intermittent access through a null pointer. r=dmajor --- hal/gonk/GonkHal.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/hal/gonk/GonkHal.cpp b/hal/gonk/GonkHal.cpp index 07482e1a89c9..36e91043b65c 100644 --- a/hal/gonk/GonkHal.cpp +++ b/hal/gonk/GonkHal.cpp @@ -1185,8 +1185,14 @@ OomVictimLogger::Observe( for (size_t i = 0; i < regex_count; i++) { int matching = !regexec(&(mRegexes[i]), line_begin, 0, NULL, 0); if (matching) { - // Log content of kernel message - line_begin = strchr(line_begin, ']') + 2; + // Log content of kernel message. We try to skip the ], but if for + // some reason (most likely due to buffer overflow/wraparound), we + // can't find the ] then we just log the entire line. + char* endOfTimestamp = strchr(line_begin, ']'); + if (endOfTimestamp && endOfTimestamp[1] == ' ') { + // skip the ] and the space that follows it + line_begin = endOfTimestamp + 2; + } if (!lineTimestampFound) { OOM_LOG(ANDROID_LOG_WARN, "following kill message may be a duplicate"); }