From 2cca460cdcd69ec1bc81064a4bc5943d0e02625b Mon Sep 17 00:00:00 2001 From: Ben Magistro Date: Tue, 5 Nov 2024 00:57:21 +0000 Subject: [PATCH] fix: properly handle directories for local files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- suricata/update/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/suricata/update/main.py b/suricata/update/main.py index 7814518..f62aa07 100644 --- a/suricata/update/main.py +++ b/suricata/update/main.py @@ -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)