Skip to content

Commit 0b6f40d

Browse files
committed
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.
1 parent d63677b commit 0b6f40d

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/torcontrol.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,10 @@ static std::pair<bool,std::string> ReadBinaryFile(const fs::path &filename, size
330330
char buffer[128];
331331
size_t n;
332332
while ((n=fread(buffer, 1, sizeof(buffer), f)) > 0) {
333+
// Check for reading errors so we don't return any data if we couldn't
334+
// read the entire file (or up to maxsize)
335+
if (ferror(f))
336+
return std::make_pair(false,"");
333337
retval.append(buffer, buffer+n);
334338
if (retval.size() > maxsize)
335339
break;

0 commit comments

Comments
 (0)