From a6b84a0c57bcbdc9ce22bbd789d56ab4a0d41929 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Thu, 25 Apr 2013 00:13:39 +0200 Subject: [PATCH] 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. --- src/kits/support/BufferedDataIO.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/kits/support/BufferedDataIO.cpp b/src/kits/support/BufferedDataIO.cpp index 42299ae64e..7fb3c8f017 100644 --- a/src/kits/support/BufferedDataIO.cpp +++ b/src/kits/support/BufferedDataIO.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2011, Axel Dörfler, axeld@pinc-software.de. + * Copyright 2011-2013, Axel Dörfler, axeld@pinc-software.de. * Distributed under the terms of the MIT License. */ @@ -140,8 +140,13 @@ BBufferedDataIO::Read(void* buffer, size_t size) if (status != B_OK) return status; - TRACE("%p: read %" B_PRIuSIZE " bytes from stream\n", this, fBufferSize); - fSize = fStream.Read(fBuffer, fBufferSize); + TRACE("%p: read %" B_PRIuSIZE " bytes from stream\n", this, + 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); fPosition = 0;