Skip to content

Commit

Permalink
filter non elf files from make_sql_engine
Browse files Browse the repository at this point in the history
We should filter non elf files from make_sql_engine otherwise the
NoneType gets passed down to the generators.

* added unit test
  • Loading branch information
fzakaria committed Sep 25, 2023
1 parent 5b58e6e commit badad1b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion sqlelf/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ def make_sql_engine(filenames: list[str], recursive: bool = False) -> SQLEngine:
recursive: whether to recursively load all shared
libraries needed by each binary
"""
binaries: list[lief.Binary] = [lief.parse(filename) for filename in filenames]
binaries: list[lief.Binary] = [
lief.parse(filename) for filename in filenames if lief.is_elf(filename)
]
connection = apsw.Connection(":memory:")

if recursive:
Expand Down
6 changes: 6 additions & 0 deletions tests/test_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,9 @@ def test_select_zero_rows() -> None:
engine = sql.make_sql_engine(["/bin/ls"])
result = list(engine.execute("SELECT * FROM elf_headers LIMIT 0"))
assert len(result) == 0


def test_non_existent_file() -> None:
engine = sql.make_sql_engine(["/doesnotexist"])
result = list(engine.execute("SELECT * FROM elf_headers LIMIT 1"))
assert len(result) == 0

0 comments on commit badad1b

Please sign in to comment.