]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
eve: no need to check fields
authorVictor Julien <vjulien@oisf.net>
Thu, 20 Apr 2023 18:23:10 +0000 (20:23 +0200)
committerVictor Julien <vjulien@oisf.net>
Mon, 24 Apr 2023 05:17:22 +0000 (07:17 +0200)
Cppcheck 2.10:

src/output-json-dns.c:460:23: warning: Identical inner 'if' condition is always true (outer condition is 'field' and inner condition is 'field!=NULL'). [identicalInnerCondition]
            if (field != NULL)
                      ^
src/output-json-dns.c:458:9: note: outer condition: field
        TAILQ_FOREACH(field, &custom->head, next)
        ^
src/output-json-dns.c:460:23: note: identical inner condition: field!=NULL
            if (field != NULL)
                      ^

src/output-json-email-common.c:408:27: warning: Identical inner 'if' condition is always true (outer condition is 'field' and inner condition is 'field!=NULL'). [identicalInnerCondition]
                if (field != NULL) {
                          ^
src/output-json-email-common.c:407:13: note: outer condition: field
            TAILQ_FOREACH(field, &custom->head, next) {
            ^
src/output-json-email-common.c:408:27: note: identical inner condition: field!=NULL
                if (field != NULL) {
                          ^
src/output-json-email-common.c:430:27: warning: Identical inner 'if' condition is always true (outer condition is 'field' and inner condition is 'field!=NULL'). [identicalInnerCondition]
                if (field != NULL) {
                          ^
src/output-json-email-common.c:429:13: note: outer condition: field
            TAILQ_FOREACH(field, &md5_conf->head, next) {
            ^
src/output-json-email-common.c:430:27: note: identical inner condition: field!=NULL
                if (field != NULL) {
                          ^
src/output-json-http.c:574:27: warning: Identical inner 'if' condition is always true (outer condition is 'field' and inner condition is 'field!=NULL'). [identicalInnerCondition]
                if (field != NULL)
                          ^
src/output-json-http.c:572:13: note: outer condition: field
            TAILQ_FOREACH(field, &custom->head, next)
            ^
src/output-json-http.c:574:27: note: identical inner condition: field!=NULL
                if (field != NULL)
                          ^

src/output-json-dns.c
src/output-json-email-common.c
src/output-json-http.c

index ab7cf8edfe552bfd2d430008248721081011507d..40ffa6460209345668fa4366ad59b1ce92432c42 100644 (file)
@@ -455,19 +455,12 @@ static void JsonDnsLogParseConfig(LogDnsFileCtx *dnslog_ctx, ConfNode *conf,
     if ((custom = ConfNodeLookupChild(conf, answer_types_key)) != NULL) {
         dnslog_ctx->flags &= ~LOG_ALL_RRTYPES;
         ConfNode *field;
-        TAILQ_FOREACH(field, &custom->head, next)
-        {
-            if (field != NULL)
-            {
-                DnsRRTypes f;
-                for (f = DNS_RRTYPE_A; f < DNS_RRTYPE_MAX; f++)
-                {
-                    if (strcasecmp(dns_rrtype_fields[f].config_rrtype,
-                                   field->val) == 0)
-                    {
-                        dnslog_ctx->flags |= dns_rrtype_fields[f].flags;
-                        break;
-                    }
+        TAILQ_FOREACH (field, &custom->head, next) {
+            DnsRRTypes f;
+            for (f = DNS_RRTYPE_A; f < DNS_RRTYPE_MAX; f++) {
+                if (strcasecmp(dns_rrtype_fields[f].config_rrtype, field->val) == 0) {
+                    dnslog_ctx->flags |= dns_rrtype_fields[f].flags;
+                    break;
                 }
             }
         }
index 565468b5e165f756506069eee4470ca1d35b1e94..cb21a85e7d9a62ab3cc72ee88135662f18ea0d71 100644 (file)
@@ -404,20 +404,15 @@ void OutputEmailInitConf(ConfNode *conf, OutputJsonEmailCtx *email_ctx)
         ConfNode *custom;
         if ((custom = ConfNodeLookupChild(conf, "custom")) != NULL) {
             ConfNode *field;
-            TAILQ_FOREACH(field, &custom->head, next) {
-                if (field != NULL) {
-                    int f = 0;
-                    while(email_fields[f].config_field) {
-                        if ((strcmp(email_fields[f].config_field,
-                                   field->val) == 0) ||
-                            (strcasecmp(email_fields[f].email_field,
-                                        field->val) == 0))
-                        {
-                            email_ctx->fields |= (1ULL<<f);
-                            break;
-                        }
-                        f++;
+            TAILQ_FOREACH (field, &custom->head, next) {
+                int f = 0;
+                while (email_fields[f].config_field) {
+                    if ((strcmp(email_fields[f].config_field, field->val) == 0) ||
+                            (strcasecmp(email_fields[f].email_field, field->val) == 0)) {
+                        email_ctx->fields |= (1ULL << f);
+                        break;
                     }
+                    f++;
                 }
             }
         }
@@ -426,16 +421,14 @@ void OutputEmailInitConf(ConfNode *conf, OutputJsonEmailCtx *email_ctx)
         ConfNode *md5_conf;
         if ((md5_conf = ConfNodeLookupChild(conf, "md5")) != NULL) {
             ConfNode *field;
-            TAILQ_FOREACH(field, &md5_conf->head, next) {
-                if (field != NULL) {
-                    if (strcmp("body", field->val) == 0) {
-                        SCLogInfo("Going to log the md5 sum of email body");
-                        email_ctx->flags |= LOG_EMAIL_BODY_MD5;
-                    }
-                    if (strcmp("subject", field->val) == 0) {
-                        SCLogInfo("Going to log the md5 sum of email subject");
-                        email_ctx->flags |= LOG_EMAIL_SUBJECT_MD5;
-                    }
+            TAILQ_FOREACH (field, &md5_conf->head, next) {
+                if (strcmp("body", field->val) == 0) {
+                    SCLogInfo("Going to log the md5 sum of email body");
+                    email_ctx->flags |= LOG_EMAIL_BODY_MD5;
+                }
+                if (strcmp("subject", field->val) == 0) {
+                    SCLogInfo("Going to log the md5 sum of email subject");
+                    email_ctx->flags |= LOG_EMAIL_SUBJECT_MD5;
                 }
             }
         }
index 0dbbfee7d19e3fb87cb971252f48e846f7ba4aeb..e12555375bfad5f48acc0d6733b9e2280dd33ff6 100644 (file)
@@ -569,21 +569,13 @@ static OutputInitResult OutputHttpLogInitSub(ConfNode *conf, OutputCtx *parent_c
         ConfNode *custom;
         if ((custom = ConfNodeLookupChild(conf, "custom")) != NULL) {
             ConfNode *field;
-            TAILQ_FOREACH(field, &custom->head, next)
-            {
-                if (field != NULL)
-                {
-                    HttpField f;
-                    for (f = HTTP_FIELD_ACCEPT; f < HTTP_FIELD_SIZE; f++)
-                    {
-                        if ((strcmp(http_fields[f].config_field,
-                                   field->val) == 0) ||
-                            (strcasecmp(http_fields[f].htp_field,
-                                        field->val) == 0))
-                        {
-                            http_ctx->fields |= (1ULL<<f);
-                            break;
-                        }
+            TAILQ_FOREACH (field, &custom->head, next) {
+                HttpField f;
+                for (f = HTTP_FIELD_ACCEPT; f < HTTP_FIELD_SIZE; f++) {
+                    if ((strcmp(http_fields[f].config_field, field->val) == 0) ||
+                            (strcasecmp(http_fields[f].htp_field, field->val) == 0)) {
+                        http_ctx->fields |= (1ULL << f);
+                        break;
                     }
                 }
             }