]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
fix: Check for short reads in Reader::read_str (#1068)
authorGregor Jasny <gregor.jasny@goto.com>
Sun, 8 May 2022 14:08:43 +0000 (16:08 +0200)
committerGitHub <noreply@github.com>
Sun, 8 May 2022 14:08:43 +0000 (16:08 +0200)
src/core/Reader.hpp

index a352b9a5471d77eaa2835a63f2ecff7ae7d0800c..291c356270db4d1af88226f1df32de56642a0cfe 100644 (file)
@@ -72,7 +72,12 @@ inline std::string
 Reader::read_str(const size_t length)
 {
   std::string value(length, 0);
-  read(&value[0], length);
+  if (length > 0) {
+    const auto bytes_read = read(&value[0], length);
+    if (bytes_read != length) {
+      throw core::Error("Read underflow");
+    }
+  }
   return value;
 }