Fix undefined behaviour, calling memcpy with NULL pointer.

Identified as part of audit: Least Authority, Issue D.
This commit is contained in:
Simon 2018-04-30 16:41:02 -07:00
parent 1878f3a759
commit 54a872f0fa
1 changed files with 10 additions and 0 deletions

View File

@ -230,6 +230,10 @@ public:
{
if (nSize == 0) return;
if (pch == nullptr) {
throw std::ios_base::failure("CBaseDataStream::read(): cannot read from null pointer");
}
// Read from the beginning of the buffer
unsigned int nReadPosNext = nReadPos + nSize;
if (nReadPosNext >= vch.size())
@ -519,6 +523,12 @@ public:
// read a number of bytes
void read(char *pch, size_t nSize) {
if (nSize == 0) return;
if (pch == nullptr) {
throw std::ios_base::failure("CBufferedFile::read(): cannot read from null pointer");
}
if (nSize + nReadPos > nReadLimit)
throw std::ios_base::failure("Read attempted past buffer limit");
if (nSize + nRewind > vchBuf.size())