Add an assertion check in readAll

If the assertion could fail somehow, we could have memory unsafety.
This commit is contained in:
Ryan Prichard 2017-01-03 20:18:29 -06:00
parent 91fce49ab1
commit 9f0d7e6b4e

View File

@ -342,7 +342,8 @@ static size_t readData(winpty_t &wp, void *data, size_t amount) {
static void readAll(winpty_t &wp, void *data, size_t amount) { static void readAll(winpty_t &wp, void *data, size_t amount) {
while (amount > 0) { while (amount > 0) {
size_t chunk = readData(wp, data, amount); const size_t chunk = readData(wp, data, amount);
ASSERT(chunk <= amount && "readData result is larger than amount");
data = reinterpret_cast<char*>(data) + chunk; data = reinterpret_cast<char*>(data) + chunk;
amount -= chunk; amount -= chunk;
} }