Browse Source

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.
0.15
Jack Grigg 8 years ago
parent
commit
0b6f40d4ca
No known key found for this signature in database
GPG Key ID: 665DBCD284F7DAFF
  1. 4
      src/torcontrol.cpp

4
src/torcontrol.cpp

@ -330,6 +330,10 @@ static std::pair<bool,std::string> ReadBinaryFile(const fs::path &filename, size @@ -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;

Loading…
Cancel
Save