]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
detect-file-hash: drop redundant rule_file NULL check
authorBoris Tonofa <b.tonofa@ideco.ru>
Mon, 30 Jun 2025 13:10:15 +0000 (16:10 +0300)
committerVictor Julien <victor@inliniac.net>
Wed, 27 Aug 2025 06:42:33 +0000 (08:42 +0200)
de_ctx->rule_file is never NULL inside DetectFileHashParse(); add a comment
stating this fact and remove the superfluous NULL guard.

No functional change – the patch only clarifies the code and trims a few
lines of dead code.

Bug 7769

src/detect-file-hash-common.c

index 15f94ee6bd64c79d8c0ed44a456bc39c1da13766..d18756eb8f0fad8dbea55b448e45ff840a7b133f 100644 (file)
@@ -230,6 +230,8 @@ static DetectFileHashData *DetectFileHashParse (const DetectEngineCtx *de_ctx,
         goto error;
     }
 
+    /* de_ctx->rule_file is already set by the rule loader before this
+     * function is called, so it is guaranteed to be non-NULL here. */
     rule_filename = SCStrdup(de_ctx->rule_file);
     if (rule_filename == NULL) {
         goto error;
@@ -239,16 +241,14 @@ static DetectFileHashData *DetectFileHashParse (const DetectEngineCtx *de_ctx,
     fp = fopen(filename, "r");
     if (fp == NULL) {
 #ifdef HAVE_LIBGEN_H
-        if (de_ctx->rule_file != NULL) {
-            char *dir = dirname(rule_filename);
-            if (dir != NULL) {
-                char path[PATH_MAX];
-                snprintf(path, sizeof(path), "%s/%s", dir, str);
-                fp = fopen(path, "r");
-                if (fp == NULL) {
-                    SCLogError("opening hash file %s: %s", path, strerror(errno));
-                    goto error;
-                }
+        char *dir = dirname(rule_filename);
+        if (dir != NULL) {
+            char path[PATH_MAX];
+            snprintf(path, sizeof(path), "%s/%s", dir, str);
+            fp = fopen(path, "r");
+            if (fp == NULL) {
+                SCLogError("opening hash file %s: %s", path, strerror(errno));
+                goto error;
             }
         }
         if (fp == NULL) {