Commit 6a7911e4bd9c224ba934eca5d6157de2e57d20e7

Authored by Christian Herdtweck
1 parent 626bcdcb

olevba: Make clean-up more error-proof

Might otherwise try to delete a non-existent file
Showing 1 changed file with 6 additions and 1 deletions
oletools/olevba.py
@@ -4062,8 +4062,13 @@ def process_file(filename, data, container, options, crypto_nesting=0): @@ -4062,8 +4062,13 @@ def process_file(filename, data, container, options, crypto_nesting=0):
4062 except Exception: 4062 except Exception:
4063 raise 4063 raise
4064 finally: # clean up 4064 finally: # clean up
4065 - if decrypted_file is not None and os.path.isfile(decrypted_file): 4065 + try:
  4066 + log.debug('Removing crypt temp file {}'.format(decrypted_file))
4066 os.unlink(decrypted_file) 4067 os.unlink(decrypted_file)
  4068 + except Exception: # e.g. file does not exist or is None
  4069 + pass
  4070 + # no idea what to return now
  4071 + raise Exception('Programming error -- should never have reached this!')
4067 4072
4068 4073
4069 def main(cmd_line_args=None): 4074 def main(cmd_line_args=None):