Skip to content

Commit

Permalink
Changes to not catch exception related to coding errors
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimmetz committed Apr 4, 2020
1 parent f81839b commit e84237d
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 3 deletions.
7 changes: 7 additions & 0 deletions plaso/engine/single_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def __init__(self):
self._processing_configuration = None
self._status_update_callback = None

# pylint: disable=missing-raises-doc
def _ProcessPathSpec(self, extraction_worker, parser_mediator, path_spec):
"""Processes a path specification.
Expand All @@ -49,10 +50,16 @@ def _ProcessPathSpec(self, extraction_worker, parser_mediator, path_spec):
excluded_find_specs = (
self.collection_filters_helper.excluded_file_system_find_specs)

# pylint: disable=try-except-raise
try:
extraction_worker.ProcessPathSpec(
parser_mediator, path_spec, excluded_find_specs=excluded_find_specs)

# Raise on coding errors.
except (AttributeError, ImportError, NameError, TypeError,
UnboundLocalError):
raise

except KeyboardInterrupt:
self._abort = True

Expand Down
6 changes: 6 additions & 0 deletions plaso/multi_processing/analysis_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ def _Main(self):

storage_writer.WriteTaskStart()

# pylint: disable=try-except-raise
try:
logger.debug(
'{0!s} (PID: {1:d}) started monitoring event queue.'.format(
Expand Down Expand Up @@ -178,6 +179,11 @@ def _Main(self):

self._analysis_mediator.ProduceAnalysisReport(self._analysis_plugin)

# Raise on coding errors.
except (AttributeError, ImportError, NameError, TypeError,
UnboundLocalError):
raise

# All exceptions need to be caught here to prevent the process
# from being killed by an uncaught exception.
except Exception as exception: # pylint: disable=broad-except
Expand Down
13 changes: 13 additions & 0 deletions plaso/multi_processing/worker_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ def _Main(self):

self._status = definitions.STATUS_INDICATOR_RUNNING

# pylint: disable=try-except-raise
try:
logger.debug('{0!s} (PID: {1:d}) started monitoring task queue.'.format(
self._name, self._pid))
Expand All @@ -189,6 +190,11 @@ def _Main(self):
logger.debug('{0!s} (PID: {1:d}) stopped monitoring task queue.'.format(
self._name, self._pid))

# Raise on coding errors.
except (AttributeError, ImportError, NameError, TypeError,
UnboundLocalError):
raise

# All exceptions need to be caught here to prevent the process
# from being killed by an uncaught exception.
except Exception as exception: # pylint: disable=broad-except
Expand Down Expand Up @@ -228,6 +234,7 @@ def _Main(self):
except errors.QueueAlreadyClosed:
logger.error('Queue for {0:s} was already closed.'.format(self.name))

# pylint: disable=missing-raises-doc
def _ProcessPathSpec(self, extraction_worker, parser_mediator, path_spec):
"""Processes a path specification.
Expand All @@ -244,10 +251,16 @@ def _ProcessPathSpec(self, extraction_worker, parser_mediator, path_spec):
excluded_find_specs = (
self._collection_filters_helper.excluded_file_system_find_specs)

# pylint: disable=try-except-raise
try:
extraction_worker.ProcessPathSpec(
parser_mediator, path_spec, excluded_find_specs=excluded_find_specs)

# Raise on coding errors.
except (AttributeError, ImportError, NameError, TypeError,
UnboundLocalError):
raise

except dfvfs_errors.CacheFullError:
# TODO: signal engine of failure.
self._abort = True
Expand Down
8 changes: 8 additions & 0 deletions plaso/parsers/esedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def GetFormatSpecification(cls):
format_specification.AddNewSignature(b'\xef\xcd\xab\x89', offset=4)
return format_specification

# pylint: disable=missing-raises-doc
def ParseFileObject(self, parser_mediator, file_object):
"""Parses an ESE database file-like object.
Expand All @@ -79,6 +80,7 @@ def ParseFileObject(self, parser_mediator, file_object):

# Compare the list of available plugin objects.
cache = ESEDBCache()

try:
table_names = frozenset(self._GetTableNames(esedb_file))

Expand All @@ -89,10 +91,16 @@ def ParseFileObject(self, parser_mediator, file_object):
if not plugin.required_tables.issubset(table_names):
continue

# pylint: disable=try-except-raise
try:
plugin.UpdateChainAndProcess(
parser_mediator, cache=cache, database=esedb_file)

# Raise on coding errors.
except (AttributeError, ImportError, NameError, TypeError,
UnboundLocalError):
raise

except Exception as exception: # pylint: disable=broad-except
parser_mediator.ProduceExtractionWarning((
'plugin: {0:s} unable to parse ESE database with error: '
Expand Down
7 changes: 7 additions & 0 deletions plaso/parsers/esedb_plugins/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ def _GetRecordValue(self, record, value_entry):
return long_value.get_data()
return record.get_value_data(value_entry)

# pylint: disable=missing-raises-doc
def _GetRecordValues(
self, parser_mediator, table_name, record, value_mappings=None):
"""Retrieves the values from the record.
Expand Down Expand Up @@ -260,10 +261,16 @@ def _GetRecordValues(
self.NAME, value_callback_method, column_name, table_name))

if value_callback:
# pylint: disable=try-except-raise
try:
value_data = record.get_value_data(value_entry)
value = value_callback(value_data)

# Raise on coding errors.
except (AttributeError, ImportError, NameError, TypeError,
UnboundLocalError):
raise

except Exception as exception: # pylint: disable=broad-except
logger.error(exception)
value = None
Expand Down
13 changes: 13 additions & 0 deletions plaso/parsers/olecf.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def GetFormatSpecification(cls):

return format_specification

# pylint: disable=missing-raises-doc
def ParseFileObject(self, parser_mediator, file_object):
"""Parses an OLE Compound File (OLECF) file-like object.
Expand Down Expand Up @@ -81,19 +82,31 @@ def ParseFileObject(self, parser_mediator, file_object):
if not plugin.REQUIRED_ITEMS.issubset(item_names):
continue

# pylint: disable=try-except-raise
try:
plugin.UpdateChainAndProcess(parser_mediator, root_item=root_item)

# Raise on coding errors.
except (AttributeError, ImportError, NameError, TypeError,
UnboundLocalError):
raise

except Exception as exception: # pylint: disable=broad-except
parser_mediator.ProduceExtractionWarning((
'plugin: {0:s} unable to parse OLECF file with error: '
'{1!s}').format(plugin.NAME, exception))

if self._default_plugin and not parser_mediator.abort:
# pylint: disable=try-except-raise
try:
self._default_plugin.UpdateChainAndProcess(
parser_mediator, root_item=root_item)

# Raise on coding errors.
except (AttributeError, ImportError, NameError, TypeError,
UnboundLocalError):
raise

except Exception as exception: # pylint: disable=broad-except
parser_mediator.ProduceExtractionWarning((
'plugin: {0:s} unable to parse OLECF file with error: '
Expand Down
7 changes: 7 additions & 0 deletions plaso/parsers/safari_cookies.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def _ParsePage(self, parser_mediator, file_offset, page_data):

self._ParseRecord(parser_mediator, page_data, record_offset)

# pylint: disable=missing-raises-doc
def _ParseRecord(self, parser_mediator, page_data, record_offset):
"""Parses a record from the page data.
Expand Down Expand Up @@ -178,11 +179,17 @@ def _ParseRecord(self, parser_mediator, page_data, record_offset):
if event_data.cookie_name != plugin.COOKIE_NAME:
continue

# pylint: disable=try-except-raise
try:
plugin.UpdateChainAndProcess(
parser_mediator, cookie_name=event_data.cookie_name,
cookie_data=event_data.cookie_value, url=event_data.url)

# Raise on coding errors.
except (AttributeError, ImportError, NameError, TypeError,
UnboundLocalError):
raise

except Exception as exception: # pylint: disable=broad-except
parser_mediator.ProduceExtractionWarning(
'plugin: {0:s} unable to parse cookie with error: {1!s}'.format(
Expand Down
12 changes: 12 additions & 0 deletions plaso/parsers/sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ def GetFormatSpecification(cls):
format_specification.AddNewSignature(b'SQLite format 3', offset=0)
return format_specification

# pylint: disable=missing-raises-doc
def ParseFileEntry(self, parser_mediator, file_entry):
"""Parses a SQLite database file entry.
Expand Down Expand Up @@ -464,11 +465,17 @@ def ParseFileEntry(self, parser_mediator, file_entry):
parser_mediator.SetFileEntry(file_entry)
parser_mediator.AddEventAttribute('schema_match', schema_match)

# pylint: disable=try-except-raise
try:
plugin.UpdateChainAndProcess(
parser_mediator, cache=cache, database=database,
database_wal=database_wal, wal_file_entry=wal_file_entry)

# Raise on coding errors.
except (AttributeError, ImportError, NameError, TypeError,
UnboundLocalError):
raise

except Exception as exception: # pylint: disable=broad-except
parser_mediator.ProduceExtractionWarning((
'plugin: {0:s} unable to parse SQLite database with error: '
Expand All @@ -490,6 +497,11 @@ def ParseFileEntry(self, parser_mediator, file_entry):
parser_mediator, cache=cache, database=database,
database_wal=database_wal, wal_file_entry=wal_file_entry)

# Raise on coding errors.
except (AttributeError, ImportError, NameError, TypeError,
UnboundLocalError):
raise

except Exception as exception: # pylint: disable=broad-except
parser_mediator.ProduceExtractionWarning((
'plugin: {0:s} unable to parse SQLite database and WAL with '
Expand Down
7 changes: 7 additions & 0 deletions plaso/parsers/sqlite_plugins/chrome_cookies.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def __init__(self):
self._cookie_plugins = (
cookie_plugins_manager.CookiePluginsManager.GetPlugins())

# pylint: disable=missing-raises-doc
def ParseCookieRow(self, parser_mediator, query, row, **unused_kwargs):
"""Parses a cookie row.
Expand Down Expand Up @@ -134,11 +135,17 @@ def ParseCookieRow(self, parser_mediator, query, row, **unused_kwargs):
if cookie_name != plugin.COOKIE_NAME:
continue

# pylint: disable=try-except-raise
try:
plugin.UpdateChainAndProcess(
parser_mediator, cookie_data=cookie_data, cookie_name=cookie_name,
url=url)

# Raise on coding errors.
except (AttributeError, ImportError, NameError, TypeError,
UnboundLocalError):
raise

except Exception as exception: # pylint: disable=broad-except
parser_mediator.ProduceExtractionWarning(
'plugin: {0:s} unable to parse cookie with error: {1!s}'.format(
Expand Down
7 changes: 7 additions & 0 deletions plaso/parsers/sqlite_plugins/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def _HashRow(cls, row):

return hash(' '.join(values))

# pylint: disable=missing-raises-doc
def _ParseQuery(self, parser_mediator, database, query, callback, cache):
"""Queries a database and parses the results.
Expand Down Expand Up @@ -124,9 +125,15 @@ def _ParseQuery(self, parser_mediator, database, query, callback, cache):
if row_hash in row_cache:
continue

# pylint: disable=try-except-raise
try:
callback(parser_mediator, query, row, cache=cache, database=database)

# Raise on coding errors.
except (AttributeError, ImportError, NameError, TypeError,
UnboundLocalError):
raise

except Exception as exception: # pylint: disable=broad-except
parser_mediator.ProduceExtractionWarning((
'unable to parse row: {0:d} with callback: {1:s} on database '
Expand Down
3 changes: 0 additions & 3 deletions tests/multi_processing/worker_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,6 @@ def testProcessPathSpec(self):
self.assertEqual(parser_mediator._number_of_warnings, 0)
self.assertTrue(test_process._abort)

test_process._ProcessPathSpec(None, parser_mediator, path_spec)
self.assertEqual(parser_mediator._number_of_warnings, 1)

def testProcessTask(self):
"""Tests the _ProcessTask function."""
session = sessions.Session()
Expand Down

0 comments on commit e84237d

Please sign in to comment.