From: Victor Julien Date: Thu, 20 Apr 2023 18:23:10 +0000 (+0200) Subject: eve: no need to check fields X-Git-Tag: suricata-7.0.0-rc2~373 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b700222240fc80758f6a2a788bdfd3b623fc2a0d;p=thirdparty%2Fsuricata.git eve: no need to check fields 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) ^ --- diff --git a/src/output-json-dns.c b/src/output-json-dns.c index ab7cf8edfe..40ffa64602 100644 --- a/src/output-json-dns.c +++ b/src/output-json-dns.c @@ -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; } } } diff --git a/src/output-json-email-common.c b/src/output-json-email-common.c index 565468b5e1..cb21a85e7d 100644 --- a/src/output-json-email-common.c +++ b/src/output-json-email-common.c @@ -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<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; } } } diff --git a/src/output-json-http.c b/src/output-json-http.c index 0dbbfee7d1..e12555375b 100644 --- a/src/output-json-http.c +++ b/src/output-json-http.c @@ -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<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; } } }