BBufferedDataIO: the underlying stream might return an error.

* In this case, fSize would have been set incorrectly, ignoring the error
  completely, but open the possibility to read from uninitialized or even
  unmapped memory.
This commit is contained in:
Axel Dörfler
2015-01-06 15:25:37 +01:00
parent 3302df142e
commit a6b84a0c57
+8 -3
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2011, Axel Dörfler, [email protected]. * Copyright 2011-2013, Axel Dörfler, [email protected].
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -140,8 +140,13 @@ BBufferedDataIO::Read(void* buffer, size_t size)
if (status != B_OK) if (status != B_OK)
return status; return status;
TRACE("%p: read %" B_PRIuSIZE " bytes from stream\n", this, fBufferSize); TRACE("%p: read %" B_PRIuSIZE " bytes from stream\n", this,
fSize = fStream.Read(fBuffer, fBufferSize); fBufferSize);
ssize_t nextRead = fStream.Read(fBuffer, fBufferSize);
if (nextRead < 0)
return nextRead;
fSize = nextRead;
TRACE("%p: retrieved %" B_PRIuSIZE " bytes from stream\n", this, fSize); TRACE("%p: retrieved %" B_PRIuSIZE " bytes from stream\n", this, fSize);
fPosition = 0; fPosition = 0;