diff options
author | Gregor Jasny <gregor.jasny@goto.com> | 2022-05-08 16:08:43 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-08 16:08:43 +0200 |
commit | d96ddd06d4eb379efeef1aebd71ad4d26030eacd (patch) | |
tree | 3d551e9a432fcbc6fe2cc36fa4c7cb46870e531b | |
parent | e8aef251aa0947ad1f238d80070d39f4e05074d8 (diff) | |
download | ccache-d96ddd06d4eb379efeef1aebd71ad4d26030eacd.tar.gz |
fix: Check for short reads in Reader::read_str (#1068)
-rw-r--r-- | src/core/Reader.hpp | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/core/Reader.hpp b/src/core/Reader.hpp index a352b9a5..291c3562 100644 --- a/src/core/Reader.hpp +++ b/src/core/Reader.hpp @@ -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; } |