crash-reporter: accept kernel dmesg records with no ramoops header

pstore compression has been added since kernel 3.12. In order to
decompress dmesg correctly, ramoops driver has to strip the header
before handing over the record to the pstore driver, so we don't
need to do it in KernelCollector anymore.

The corresponding kernel patch is at
https://chromium-review.googlesource.com/#/c/211389

BUG=chromium:392248
TEST=platform_KernelErrorPaths passed on 3.14 kernel

Change-Id: If1bec43e640e0978c7573cc90befc6d68072373c
Signed-off-by: Ben Zhang <benzh@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/211460
Reviewed-by: Kees Cook <keescook@chromium.org>
diff --git a/crash_reporter/kernel_collector.cc b/crash_reporter/kernel_collector.cc
index cd684ff..98b3e8f 100644
--- a/crash_reporter/kernel_collector.cc
+++ b/crash_reporter/kernel_collector.cc
@@ -96,14 +96,18 @@
     return false;
   }
 
+  *record_found = true;
   if (record_re.FullMatch(record, &captured)) {
     // Found a match, append it to the content, and remove from pstore.
     contents->append(captured);
-    base::DeleteFile(ramoops_record, false);
-    *record_found = true;
   } else {
-    *record_found = false;
+    // pstore compression has been added since kernel 3.12. In order to
+    // decompress dmesg correctly, ramoops driver has to strip the header
+    // before handing over the record to the pstore driver, so we don't
+    // need to do it here anymore.
+    contents->append(record);
   }
+  base::DeleteFile(ramoops_record, false);
 
   return true;
 }
diff --git a/crash_reporter/kernel_collector_test.cc b/crash_reporter/kernel_collector_test.cc
index d920fc6..6284f49 100644
--- a/crash_reporter/kernel_collector_test.cc
+++ b/crash_reporter/kernel_collector_test.cc
@@ -78,10 +78,10 @@
   std::string dump;
   dump.clear();
 
-  WriteStringToFile(kcrash_file(), "emptydata");
+  WriteStringToFile(kcrash_file(), "CrashRecordWithoutRamoopsHeader");
   ASSERT_TRUE(collector_.LoadParameters());
-  ASSERT_FALSE(collector_.LoadPreservedDump(&dump));
-  ASSERT_EQ("", dump);
+  ASSERT_TRUE(collector_.LoadPreservedDump(&dump));
+  ASSERT_EQ("CrashRecordWithoutRamoopsHeader", dump);
 
   WriteStringToFile(kcrash_file(), "====1.1\nsomething");
   ASSERT_TRUE(collector_.LoadParameters());
@@ -229,14 +229,6 @@
   ASSERT_EQ(0, s_crashes);
 }
 
-TEST_F(KernelCollectorTest, CollectNoCrash) {
-  WriteStringToFile(kcrash_file(), "");
-  ASSERT_FALSE(collector_.Collect());
-  ASSERT_TRUE(FindLog("No valid records found"));
-  ASSERT_FALSE(FindLog("Stored kcrash to "));
-  ASSERT_EQ(0, s_crashes);
-}
-
 TEST_F(KernelCollectorTest, CollectBadDirectory) {
   WriteStringToFile(kcrash_file(), "====1.1\nsomething");
   ASSERT_TRUE(collector_.Collect());