summaryrefslogtreecommitdiffstats
path: root/src/deps_log.cc
diff options
context:
space:
mode:
authorLogan Chien <loganchien@google.com>2017-10-16 06:04:34 (GMT)
committerLogan Chien <loganchien@google.com>2017-10-16 06:04:34 (GMT)
commit7c80007b55fd42cdd56b06cb4330fb8ceb468e09 (patch)
tree352bfffc96a13fe85faeaf2c463ca80161e7f3bd /src/deps_log.cc
parent887eccf1fdd91d50c4761bba79b5cf329a280ffb (diff)
downloadNinja-7c80007b55fd42cdd56b06cb4330fb8ceb468e09.zip
Ninja-7c80007b55fd42cdd56b06cb4330fb8ceb468e09.tar.gz
Ninja-7c80007b55fd42cdd56b06cb4330fb8ceb468e09.tar.bz2
Fix potential buffer overrun
This commit rearranges record size comparison and fread() to make sure fread() only reads the data that can fit into the buffer.
Diffstat (limited to 'src/deps_log.cc')
-rw-r--r--src/deps_log.cc2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/deps_log.cc b/src/deps_log.cc
index 89c6023..8734dd7 100644
--- a/src/deps_log.cc
+++ b/src/deps_log.cc
@@ -209,7 +209,7 @@ bool DepsLog::Load(const string& path, State* state, string* err) {
bool is_deps = (size >> 31) != 0;
size = size & 0x7FFFFFFF;
- if (fread(buf, size, 1, f) < 1 || size > kMaxRecordSize) {
+ if (size > kMaxRecordSize || fread(buf, size, 1, f) < 1) {
read_failed = true;
break;
}