Skip to content

Commit

Permalink
hub: fix cases of TOCTOU in _open_log
Browse files Browse the repository at this point in the history
  • Loading branch information
lzaoral committed Jan 10, 2024
1 parent 2a1ae1b commit cc22141
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions kobo/hub/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,14 +402,14 @@ def _get_relative_log_path(self, name):

def _open_log(self, name):
log_path = self._get_absolute_log_path(name)
if os.path.isfile(log_path):
return io.open(log_path, 'rb', LOG_BUFFER_SIZE)
elif os.path.isfile(log_path + ".gz"):
out = gzip.open(log_path + ".gz", "rb")
out = io.BufferedReader(out, LOG_BUFFER_SIZE)
return out
else:
raise Http404('Cannot find log %s' % name)
try:
return open(log_path, 'rb', LOG_BUFFER_SIZE)
except FileNotFoundError:
try:
out = gzip.open(log_path + ".gz", "rb")
return io.BufferedReader(out, LOG_BUFFER_SIZE)
except FileNotFoundError:
raise Http404('Cannot find log %s' % name)

def get_chunk(self, name, offset=0, length=-1):
"""Returns a sequence of bytes from the named log.
Expand Down

0 comments on commit cc22141

Please sign in to comment.