OSDN Git Service

Simpleperf: check value returned by fopen.
authorYabin Cui <yabinc@google.com>
Wed, 9 Dec 2015 03:25:13 +0000 (19:25 -0800)
committerYabin Cui <yabinc@google.com>
Wed, 9 Dec 2015 03:25:13 +0000 (19:25 -0800)
Change-Id: Iecddf0b7805ccc2ad930bab2cdfcefa0702e5661

simpleperf/read_elf.cpp

index 4774ea3..a7399ce 100644 (file)
@@ -46,7 +46,10 @@ bool IsValidElfPath(const std::string& filename) {
   if (!IsRegularFile(filename)) {
     return false;
   }
-  FILE* fp = fopen(filename.c_str(), "rb");
+  FILE* fp = fopen(filename.c_str(), "reb");
+  if (fp == nullptr) {
+    return false;
+  }
   char buf[4];
   if (fread(buf, 4, 1, fp) != 1) {
     fclose(fp);