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.
This commit is contained in:
Logan Chien 2017-10-16 14:04:34 +08:00
parent 887eccf1fd
commit 7c80007b55

View File

@ -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;
}