diff options
author | Jack Grigg <jack@z.cash> | 2017-03-26 13:53:13 +1300 |
---|---|---|
committer | Jack Grigg <jack@z.cash> | 2017-05-16 18:22:19 +1200 |
commit | 0b6f40d4cabb3bebf551a49a69ce36d4b0375b6a (patch) | |
tree | e4c256b680262f336ca1787f781d39a60b19f1fe /src/torcontrol.cpp | |
parent | d63677bbb23a05feca7935c70673439705b06dca (diff) |
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.
Diffstat (limited to 'src/torcontrol.cpp')
-rw-r--r-- | src/torcontrol.cpp | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/src/torcontrol.cpp b/src/torcontrol.cpp index 0d787d16e6..bc48665f78 100644 --- a/src/torcontrol.cpp +++ b/src/torcontrol.cpp @@ -330,6 +330,10 @@ static std::pair<bool,std::string> ReadBinaryFile(const fs::path &filename, size 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; |