Skip to content

Commit

Permalink
fix: properly handle directories for local files
Browse files Browse the repository at this point in the history
When loading local files and rule files are nested in a folder, the
current behavior prepends the base path and not the nested path which
results in a file not found error. This change updates this to use the
`dirpath` parameter from `os.walk` so that it is handled correctly.

Given a structure of
  /tmp/rules/
  ├── file1.rules
  └── nested
      └── file2.rules

Today it would try to load this as the following
* /tmp/rules/file1.rules
* /tmp/rules/file2.rules

With the fix this would be
* /tmp/rules/file1.rules
* /tmp/rules/nested/file2.rules

Signed-off-by: Ben Magistro <[email protected]>
  • Loading branch information
bmagistro committed Nov 5, 2024
1 parent a81f805 commit 2cca460
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion suricata/update/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def load_local(local, files):
for dirpath, dirnames, filenames in os.walk(local):
for filename in filenames:
if filename.endswith(".rules"):
path = os.path.join(local, filename)
path = os.path.join(dirpath, filename)
load_local(path, files)
else:
local_files = glob.glob(local)
Expand Down

0 comments on commit 2cca460

Please sign in to comment.