From 3290567bbd54e01cb6fe6b1d04c659abca983af2 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Sun, 26 Mar 2017 13:53:13 +1300 Subject: [PATCH] torcontrol: Check for reading errors in ReadBinaryFile This ensures that ReadBinaryFile never returns exactly TOR_COOKIE_SIZE bytes if the file was larger than that. --- src/torcontrol.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/torcontrol.cpp b/src/torcontrol.cpp index 9898c508a..e957e38bd 100644 --- a/src/torcontrol.cpp +++ b/src/torcontrol.cpp @@ -324,6 +324,10 @@ static std::pair ReadBinaryFile(const std::string &filename, s char buffer[128]; size_t n; while ((n=fread(buffer, 1, sizeof(buffer), f)) > 0) { + // Check for reading errors so we don't return any data if we couldn't + // read the entire file (or up to maxsize) + if (ferror(f)) + return std::make_pair(false,""); retval.append(buffer, buffer+n); if (retval.size() > maxsize) break;