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.
v1.0.9-lin
Jack Grigg
7 years ago
No known key found for this signature in database
GPG Key ID: 6A6914DAFBEA00DA
1 changed files with
4 additions and
0 deletions
-
src/torcontrol.cpp
|
@ -324,6 +324,10 @@ static std::pair<bool,std::string> ReadBinaryFile(const std::string &filename, s |
|
|
char buffer[128]; |
|
|
char buffer[128]; |
|
|
size_t n; |
|
|
size_t n; |
|
|
while ((n=fread(buffer, 1, sizeof(buffer), f)) > 0) { |
|
|
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); |
|
|
retval.append(buffer, buffer+n); |
|
|
if (retval.size() > maxsize) |
|
|
if (retval.size() > maxsize) |
|
|
break; |
|
|
break; |
|
|