From: Gregor Jasny Date: Sun, 8 May 2022 14:08:43 +0000 (+0200) Subject: fix: Check for short reads in Reader::read_str (#1068) X-Git-Tag: v4.6.1~20 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d96ddd06d4eb379efeef1aebd71ad4d26030eacd;p=thirdparty%2Fccache.git fix: Check for short reads in Reader::read_str (#1068) --- diff --git a/src/core/Reader.hpp b/src/core/Reader.hpp index a352b9a54..291c35627 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; }