Skip to content

Commit

Permalink
Bugfix for SQLite plugin when "SELECT *" is used as a SELECT statement (
Browse files Browse the repository at this point in the history
log2timeline#72)

* Adding an error handling for SELECT * statements.

* Incrementing version.
  • Loading branch information
kiddinn authored Mar 19, 2019
1 parent 98497b5 commit ad81889
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion l2tscaffolder/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# -*- coding: utf-8 -*-
"""defining the version"""
__version__ = '20190130'
__version__ = '20190314'
15 changes: 15 additions & 0 deletions l2tscaffolder/scaffolders/plaso_sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ def ValidateAnswer(self, answer: dict):
'Unable to run query [{0:s}] with error: {1!s}'.format(
query_name, exception))

star_items = [x for x in query.split() if x == '*']
if star_items:
raise errors.UnableToConfigure((
'Unable to generate parser while using * to select columns. '
'Please adjust your SELECT statements to include explicit '
'column names.'))


class PlasoSQLiteScaffolder(plaso.PlasoPluginScaffolder):
"""The plaso SQLite plugin scaffolder.
Expand Down Expand Up @@ -211,6 +218,10 @@ def GenerateFiles(self) -> Iterator[Tuple[str, str]]:
Yields:
tuple: file name and content of the file to be written to disk.
Raises:
errors.UnableToConfigure: if it is not possible to generate
the files.
"""
_, _, database_name = self.test_file.rpartition(os.sep)
self.database_name = database_name
Expand All @@ -226,6 +237,10 @@ def GenerateFiles(self) -> Iterator[Tuple[str, str]]:
sql_columns[query_name] = []

for column in self._GetQueryColumns(query):
if column == '*':
raise errors.UnableToConfigure(
'Cannot use a "*" as a column name, please select a different '
'SELECT statement.')
if 'time' in column:
timestamp_columns[query_name].append(column.strip())
sql_columns[query_name].append(column)
Expand Down
2 changes: 1 addition & 1 deletion tests/other/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class VersionTest(unittest.TestCase):
def testGetVersion(self):
"""testing the get version"""
actual = l2tscaffolder.__version__
self.assertEqual('20190130', actual)
self.assertEqual('20190314', actual)


if __name__ == '__main__':
Expand Down

0 comments on commit ad81889

Please sign in to comment.