From d45ff8ebf88ef4add46a80ccdfc2d97a8b4b091b Mon Sep 17 00:00:00 2001 From: Jan Niklas Hasse Date: Fri, 30 Oct 2020 10:02:35 +0100 Subject: Check return value of setvbuf, fix #509 --- src/build_log.cc | 4 +++- src/deps_log.cc | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/build_log.cc b/src/build_log.cc index 0a2fac6..04409c8 100644 --- a/src/build_log.cc +++ b/src/build_log.cc @@ -190,7 +190,9 @@ bool BuildLog::OpenForWriteIfNeeded() { if (!log_file_) { return false; } - setvbuf(log_file_, NULL, _IOLBF, BUFSIZ); + if (setvbuf(log_file_, NULL, _IOLBF, BUFSIZ) != 0) { + return false; + } SetCloseOnExec(fileno(log_file_)); // Opening a file in append mode doesn't set the file pointer to the file's diff --git a/src/deps_log.cc b/src/deps_log.cc index 0567c95..191f300 100644 --- a/src/deps_log.cc +++ b/src/deps_log.cc @@ -413,7 +413,9 @@ bool DepsLog::OpenForWriteIfNeeded() { } // Set the buffer size to this and flush the file buffer after every record // to make sure records aren't written partially. - setvbuf(file_, NULL, _IOFBF, kMaxRecordSize + 1); + if (setvbuf(file_, NULL, _IOFBF, kMaxRecordSize + 1) != 0) { + return false; + } SetCloseOnExec(fileno(file_)); // Opening a file in append mode doesn't set the file pointer to the file's -- cgit v0.12