From 818656524003c4501401709aecffb19c28ca588c Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Wed, 2 Nov 2011 10:57:56 +0100 Subject: [PATCH] Fix a number of potential issues found by CLANG and cppcheck. --- src/alert-prelude.c | 5 +- src/app-layer-parser.c | 4 +- src/counters.c | 30 ++-- src/decode-gre.c | 12 +- src/detect-engine-address-ipv4.c | 107 ++++++-------- src/detect-engine-sigorder.c | 38 ++--- src/detect-fast-pattern.c | 132 +++++++---------- src/detect-ipproto.c | 238 ++++++++++++++++--------------- src/util-pool.c | 3 +- 9 files changed, 257 insertions(+), 312 deletions(-) diff --git a/src/alert-prelude.c b/src/alert-prelude.c index c25cd66e62..70733bd402 100644 --- a/src/alert-prelude.c +++ b/src/alert-prelude.c @@ -659,7 +659,7 @@ TmEcode AlertPrelude (ThreadVars *tv, Packet *p, void *data, PacketQueue *pq, Pa idmef_time_t *time; idmef_alert_t *alert; prelude_string_t *str; - idmef_message_t *idmef; + idmef_message_t *idmef = NULL; idmef_classification_t *class; PacketAlert *pa; @@ -748,7 +748,8 @@ TmEcode AlertPrelude (ThreadVars *tv, Packet *p, void *data, PacketQueue *pq, Pa SCReturnInt(TM_ECODE_OK); err: - idmef_message_destroy(idmef); + if (idmef != NULL) + idmef_message_destroy(idmef); SCReturnInt(TM_ECODE_FAILED); } diff --git a/src/app-layer-parser.c b/src/app-layer-parser.c index 3982b0dd9a..89cbf656cf 100644 --- a/src/app-layer-parser.c +++ b/src/app-layer-parser.c @@ -1774,6 +1774,7 @@ void AppLayerRegisterProbingParser(AlpProtoDetectCtx *ctx, { AppLayerProbingParser **probing_parsers = &ctx->probing_parsers; AppLayerProbingParserElement *pe = NULL; + AppLayerProbingParserElement *new_pe = NULL; AppLayerProbingParser *pp = NULL; /* Add info about this probing parser to our database. Also detects any @@ -1786,8 +1787,7 @@ void AppLayerRegisterProbingParser(AlpProtoDetectCtx *ctx, /* \todo introduce parsing port range here */ /* Get a new parser element */ - AppLayerProbingParserElement *new_pe = - AppLayerCreateAppLayerProbingParserElement(al_proto_name, ip_proto, + new_pe = AppLayerCreateAppLayerProbingParserElement(al_proto_name, ip_proto, al_proto, min_depth, max_depth, port, priority, top, diff --git a/src/counters.c b/src/counters.c index e0763db56d..f42711490e 100644 --- a/src/counters.c +++ b/src/counters.c @@ -400,28 +400,26 @@ static void SCPerfReleaseOPCtx() SCPerfClubTMInst *temp = NULL; pctmi = sc_perf_op_ctx->pctmi; - if (sc_perf_op_ctx != NULL) { - if (sc_perf_op_ctx->fp != NULL) - fclose(sc_perf_op_ctx->fp); + if (sc_perf_op_ctx->fp != NULL) + fclose(sc_perf_op_ctx->fp); - if (sc_perf_op_ctx->file != NULL) - SCFree(sc_perf_op_ctx->file); + if (sc_perf_op_ctx->file != NULL) + SCFree(sc_perf_op_ctx->file); - while (pctmi != NULL) { - if (pctmi->tm_name != NULL) - SCFree(pctmi->tm_name); + while (pctmi != NULL) { + if (pctmi->tm_name != NULL) + SCFree(pctmi->tm_name); - if (pctmi->head != NULL) - SCFree(pctmi->head); + if (pctmi->head != NULL) + SCFree(pctmi->head); - temp = pctmi->next; - SCFree(pctmi); - pctmi = temp; - } - - SCFree(sc_perf_op_ctx); + temp = pctmi->next; + SCFree(pctmi); + pctmi = temp; } + SCFree(sc_perf_op_ctx); + return; } diff --git a/src/decode-gre.c b/src/decode-gre.c index de5043494c..dc5271aa78 100644 --- a/src/decode-gre.c +++ b/src/decode-gre.c @@ -103,10 +103,6 @@ void DecodeGRE(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt, u if (GRE_FLAG_ISSET_ROUTE(p->greh)) { - gsre = (GRESreHdr *)(pkt + header_len); - if (gsre == NULL) - return; - while (1) { if ((header_len + GRE_SRE_HDR_LEN) > len) { @@ -114,9 +110,11 @@ void DecodeGRE(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt, u return; } + gsre = (GRESreHdr *)(pkt + header_len); + header_len += GRE_SRE_HDR_LEN; - if (gsre != NULL && (ntohs(gsre->af) == 0) && (gsre->sre_length == 0)) + if ((ntohs(gsre->af) == 0) && (gsre->sre_length == 0)) break; header_len += gsre->sre_length; @@ -124,10 +122,6 @@ void DecodeGRE(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt, u ENGINE_SET_EVENT(p, GRE_VERSION0_MALFORMED_SRE_HDR); return; } - - gsre = (GRESreHdr *)(pkt + header_len); - if (gsre == NULL) - return; } } break; diff --git a/src/detect-engine-address-ipv4.c b/src/detect-engine-address-ipv4.c index e6577786db..d48ec1b4fe 100644 --- a/src/detect-engine-address-ipv4.c +++ b/src/detect-engine-address-ipv4.c @@ -606,13 +606,18 @@ int DetectAddressJoinIPv4(DetectEngineCtx *de_ctx, DetectAddress *target, static int DetectAddressIPv4TestAddressCmp01(void) { - DetectAddress *a = DetectAddressInit(); - DetectAddress *b = DetectAddressInit(); struct in_addr in; int result = 1; - if (a == NULL || b == NULL) - goto error; + DetectAddress *a = DetectAddressInit(); + if (a == NULL) + return 0; + + DetectAddress *b = DetectAddressInit(); + if (b == NULL) { + DetectAddressFree(a); + return 0; + } if (inet_pton(AF_INET, "1.2.3.4", &in) < 0) goto error; @@ -1036,17 +1041,13 @@ static int DetectAddressIPv4TestAddressCmp01(void) b->ip2.addr_data32[0] = in.s_addr; result &= (DetectAddressCmpIPv4(a, b) != ADDRESS_GT); - if (a != NULL) - DetectAddressFree(a); - if (b != NULL) - DetectAddressFree(b); + DetectAddressFree(a); + DetectAddressFree(b); return result; error: - if (a != NULL) - DetectAddressFree(a); - if (b != NULL) - DetectAddressFree(b); + DetectAddressFree(a); + DetectAddressFree(b); return 0; } @@ -1255,12 +1256,11 @@ static int DetectAddressIPv4IsCompleteIPSpace04(void) static int DetectAddressIPv4CutNot05(void) { DetectAddress *a = NULL; - DetectAddress *b = NULL; struct in_addr in; int result = 1; if ( (a = DetectAddressInit()) == NULL) - goto error; + return 0; if (inet_pton(AF_INET, "0.0.0.0", &in) < 0) goto error; @@ -1270,29 +1270,22 @@ static int DetectAddressIPv4CutNot05(void) a->ip2.addr_data32[0] = in.s_addr; result &= (DetectAddressCutNotIPv4(a, &b) == -1); - if (a != NULL) - DetectAddressFree(a); - if (b != NULL) - DetectAddressFree(b); + DetectAddressFree(a); return result; error: - if (a != NULL) - DetectAddressFree(a); - if (b != NULL) - DetectAddressFree(b); + DetectAddressFree(a); return 0; } static int DetectAddressIPv4CutNot06(void) { DetectAddress *a = NULL; - DetectAddress *b = NULL; struct in_addr in; int result = 1; if ( (a = DetectAddressInit()) == NULL) - goto error; + return 0; if (inet_pton(AF_INET, "0.0.0.0", &in) < 0) goto error; @@ -1308,31 +1301,23 @@ static int DetectAddressIPv4CutNot06(void) if (inet_pton(AF_INET, "255.255.255.255", &in) < 0) goto error; result &= (a->ip2.addr_data32[0] = in.s_addr); - result &= (b == NULL); - if (a != NULL) - DetectAddressFree(a); - if (b != NULL) - DetectAddressFree(b); + DetectAddressFree(a); return result; error: - if (a != NULL) - DetectAddressFree(a); - if (b != NULL) - DetectAddressFree(b); + DetectAddressFree(a); return 0; } static int DetectAddressIPv4CutNot07(void) { DetectAddress *a = NULL; - DetectAddress *b = NULL; struct in_addr in; int result = 1; if ( (a = DetectAddressInit()) == NULL) - goto error; + return 0; if (inet_pton(AF_INET, "1.2.3.4", &in) < 0) goto error; @@ -1348,19 +1333,12 @@ static int DetectAddressIPv4CutNot07(void) if (inet_pton(AF_INET, "1.2.3.3", &in) < 0) goto error; result &= (a->ip2.addr_data32[0] = in.s_addr); - result &= (b == NULL); - if (a != NULL) - DetectAddressFree(a); - if (b != NULL) - DetectAddressFree(b); + DetectAddressFree(a); return result; error: - if (a != NULL) - DetectAddressFree(a); - if (b != NULL) - DetectAddressFree(b); + DetectAddressFree(a); return 0; } @@ -1372,7 +1350,7 @@ static int DetectAddressIPv4CutNot08(void) int result = 1; if ( (a = DetectAddressInit()) == NULL) - goto error; + return 0; if (inet_pton(AF_INET, "1.2.3.4", &in) < 0) goto error; @@ -1402,15 +1380,13 @@ static int DetectAddressIPv4CutNot08(void) goto error; result &= (b->ip2.addr_data32[0] = in.s_addr); - if (a != NULL) - DetectAddressFree(a); + DetectAddressFree(a); if (b != NULL) DetectAddressFree(b); return result; error: - if (a != NULL) - DetectAddressFree(a); + DetectAddressFree(a); if (b != NULL) DetectAddressFree(b); return 0; @@ -1424,7 +1400,7 @@ static int DetectAddressIPv4CutNot09(void) int result = 1; if ( (a = DetectAddressInit()) == NULL) - goto error; + return 0; if (inet_pton(AF_INET, "1.2.3.4", &in) < 0) goto error; @@ -1454,15 +1430,13 @@ static int DetectAddressIPv4CutNot09(void) goto error; result &= (b->ip2.addr_data32[0] = in.s_addr); - if (a != NULL) - DetectAddressFree(a); + DetectAddressFree(a); if (b != NULL) DetectAddressFree(b); return result; error: - if (a != NULL) - DetectAddressFree(a); + DetectAddressFree(a); if (b != NULL) DetectAddressFree(b); return 0; @@ -1470,13 +1444,18 @@ static int DetectAddressIPv4CutNot09(void) static int DetectAddressIPv4Join10(void) { - DetectAddress *source = DetectAddressInit(); - DetectAddress *target = DetectAddressInit(); struct in_addr in; int result = 1; - if (source == NULL || target == NULL) - goto error; + DetectAddress *source = DetectAddressInit(); + if (source == NULL) + return 0; + + DetectAddress *target = DetectAddressInit(); + if (target == NULL) { + DetectAddressFree(source); + return 0; + } if (inet_pton(AF_INET, "128.51.61.124", &in) < 0) goto error; @@ -1588,17 +1567,13 @@ static int DetectAddressIPv4Join10(void) goto error; result &= (target->ip2.addr_data32[0] == in.s_addr); - if (source != NULL) - DetectAddressFree(source); - if (target != NULL) - DetectAddressFree(target); + DetectAddressFree(source); + DetectAddressFree(target); return result; error: - if (source != NULL) - DetectAddressFree(source); - if (target != NULL) - DetectAddressFree(target); + DetectAddressFree(source); + DetectAddressFree(target); return 0; } diff --git a/src/detect-engine-sigorder.c b/src/detect-engine-sigorder.c index 4aa145f7a4..8a01d9f0bc 100644 --- a/src/detect-engine-sigorder.c +++ b/src/detect-engine-sigorder.c @@ -296,6 +296,9 @@ static void SCSigOrderByAction(DetectEngineCtx *de_ctx, SCSigSignatureWrapper *max = NULL; SCSigSignatureWrapper *prev = NULL; + if (sw == NULL) + return; + if (de_ctx->sc_sig_sig_wrapper == NULL) { de_ctx->sc_sig_sig_wrapper = sw; sw->min = NULL; @@ -364,8 +367,6 @@ static void SCSigOrderByAction(DetectEngineCtx *de_ctx, } /* set the min signature for this keyword, for the next ordering function */ - if (sw == NULL) - return; min = sw; while (min != NULL && min != sw->min) { if (min->sig->action != sw->sig->action) @@ -376,8 +377,6 @@ static void SCSigOrderByAction(DetectEngineCtx *de_ctx, sw->min = min; /* set the max signature for this keyword + 1, for the next ordering func */ - if (sw == NULL) - return; max = sw; while (max != NULL && max != sw->max) { if (max->sig->action != sw->sig->action) @@ -404,6 +403,9 @@ static void SCSigOrderByFlowbits(DetectEngineCtx *de_ctx, SCSigSignatureWrapper *max = NULL; SCSigSignatureWrapper *prev = NULL; + if (sw == NULL) + return; + if (de_ctx->sc_sig_sig_wrapper == NULL) { de_ctx->sc_sig_sig_wrapper = sw; sw->min = NULL; @@ -473,8 +475,6 @@ static void SCSigOrderByFlowbits(DetectEngineCtx *de_ctx, } /* set the min signature for this keyword, for the next ordering function */ - if (sw == NULL) - return; min = sw; while (min != NULL && min != sw->min) { if ( *((int *)(sw->user[SC_RADIX_USER_DATA_FLOWBITS])) != @@ -486,8 +486,6 @@ static void SCSigOrderByFlowbits(DetectEngineCtx *de_ctx, sw->min = min; /* set the max signature for this keyword + 1, for the next ordering func */ - if (sw == NULL) - return; max = sw; while (max!= NULL && max != sw->max) { if ( *((int *)(sw->user[SC_RADIX_USER_DATA_FLOWBITS])) != @@ -516,6 +514,9 @@ static void SCSigOrderByFlowvar(DetectEngineCtx *de_ctx, SCSigSignatureWrapper *max = NULL; SCSigSignatureWrapper *prev = NULL; + if (sw == NULL) + return; + if (de_ctx->sc_sig_sig_wrapper == NULL) { de_ctx->sc_sig_sig_wrapper = sw; sw->min = NULL; @@ -585,8 +586,6 @@ static void SCSigOrderByFlowvar(DetectEngineCtx *de_ctx, } /* set the min signature for this keyword, for the next ordering function */ - if (sw == NULL) - return; min = sw; while (min != NULL && min != sw->min) { if ( *((int *)(sw->user[SC_RADIX_USER_DATA_FLOWVAR])) != @@ -598,8 +597,6 @@ static void SCSigOrderByFlowvar(DetectEngineCtx *de_ctx, sw->min = min; /* set the max signature for this keyword + 1, for the next ordering func */ - if (sw == NULL) - return; max = sw; while (max != NULL && max != sw->max) { if ( *((int *)(sw->user[SC_RADIX_USER_DATA_FLOWVAR])) != @@ -627,6 +624,9 @@ static void SCSigOrderByPktvar(DetectEngineCtx *de_ctx, SCSigSignatureWrapper *max = NULL; SCSigSignatureWrapper *prev = NULL; + if (sw == NULL) + return; + if (de_ctx->sc_sig_sig_wrapper == NULL) { de_ctx->sc_sig_sig_wrapper = sw; sw->min = NULL; @@ -695,9 +695,6 @@ static void SCSigOrderByPktvar(DetectEngineCtx *de_ctx, } /* set the min signature for this keyword, for the next ordering function */ - if (sw == NULL) - return; - min = sw; while (min != NULL && min != sw->min) { if ( *((int *)(sw->user[SC_RADIX_USER_DATA_PKTVAR])) != @@ -709,8 +706,6 @@ static void SCSigOrderByPktvar(DetectEngineCtx *de_ctx, sw->min = min; /* set the max signature for this keyword + 1, for the next ordering func */ - if (sw == NULL) - return; max = sw; while (max != NULL && max != sw->max) { if ( *((int *)(sw->user[SC_RADIX_USER_DATA_PKTVAR])) != @@ -738,6 +733,9 @@ static void SCSigOrderByPriority(DetectEngineCtx *de_ctx, SCSigSignatureWrapper *max = NULL; SCSigSignatureWrapper *prev = NULL; + if (sw == NULL) + return; + if (de_ctx->sc_sig_sig_wrapper == NULL) { de_ctx->sc_sig_sig_wrapper = sw; sw->min = NULL; @@ -806,9 +804,6 @@ static void SCSigOrderByPriority(DetectEngineCtx *de_ctx, } /* set the min signature for this keyword, for the next ordering function */ - if (sw == NULL) - return; - min = sw; while (min != NULL && min != sw->min) { if (min->sig->prio != sw->sig->prio) @@ -819,9 +814,6 @@ static void SCSigOrderByPriority(DetectEngineCtx *de_ctx, sw->min = min; /* set the max signature for this keyword + 1, for the next ordering func */ - if (sw == NULL) - return; - max = sw; while (max != NULL && max != sw->max) { if (max->sig->prio != sw->sig->prio) diff --git a/src/detect-fast-pattern.c b/src/detect-fast-pattern.c index 91e9c77acc..e963c83952 100644 --- a/src/detect-fast-pattern.c +++ b/src/detect-fast-pattern.c @@ -1151,7 +1151,7 @@ int DetectFastPatternTest17(void) result = 0; sm = de_ctx->sig_list->sm_lists[DETECT_SM_LIST_PMATCH]; DetectContentData *cd = sm->ctx; - if (sm != NULL && sm->type == DETECT_CONTENT) { + if (sm->type == DETECT_CONTENT) { if (cd->flags & DETECT_CONTENT_FAST_PATTERN && cd->flags & DETECT_CONTENT_FAST_PATTERN_ONLY && !(cd->flags & cd->flags & DETECT_CONTENT_FAST_PATTERN_CHOP) && @@ -1187,7 +1187,7 @@ int DetectFastPatternTest18(void) result = 0; sm = de_ctx->sig_list->sm_lists[DETECT_SM_LIST_PMATCH]; DetectContentData *cd = sm->ctx; - if (sm != NULL && sm->type == DETECT_CONTENT) { + if (sm->type == DETECT_CONTENT) { if (cd->flags & DETECT_CONTENT_FAST_PATTERN && !(cd->flags & DETECT_CONTENT_FAST_PATTERN_ONLY) && cd->flags & cd->flags & DETECT_CONTENT_FAST_PATTERN_CHOP && @@ -2198,7 +2198,7 @@ int DetectFastPatternTest56(void) result = 0; sm = de_ctx->sig_list->sm_lists[DETECT_SM_LIST_UMATCH]; DetectContentData *ud = sm->ctx; - if (sm != NULL && sm->type == DETECT_URICONTENT) { + if (sm->type == DETECT_URICONTENT) { if (ud->flags & DETECT_CONTENT_FAST_PATTERN && ud->flags & DETECT_CONTENT_FAST_PATTERN_ONLY && !(ud->flags & DETECT_CONTENT_FAST_PATTERN_CHOP) && @@ -2234,7 +2234,7 @@ int DetectFastPatternTest57(void) result = 0; sm = de_ctx->sig_list->sm_lists[DETECT_SM_LIST_UMATCH]; DetectContentData *ud = sm->ctx; - if (sm != NULL && sm->type == DETECT_URICONTENT) { + if (sm->type == DETECT_URICONTENT) { if (ud->flags & DETECT_CONTENT_FAST_PATTERN && !(ud->flags & DETECT_CONTENT_FAST_PATTERN_ONLY) && ud->flags & DETECT_CONTENT_FAST_PATTERN_CHOP && @@ -3279,7 +3279,7 @@ int DetectFastPatternTest96(void) result = 0; sm = de_ctx->sig_list->sm_lists[DETECT_SM_LIST_UMATCH]; DetectContentData *ud = sm->ctx; - if (sm != NULL && sm->type == DETECT_URICONTENT) { + if (sm->type == DETECT_URICONTENT) { if (ud->flags & DETECT_CONTENT_FAST_PATTERN && ud->flags & DETECT_CONTENT_FAST_PATTERN_ONLY && !(ud->flags & DETECT_CONTENT_FAST_PATTERN_CHOP) && @@ -3315,7 +3315,7 @@ int DetectFastPatternTest97(void) result = 0; sm = de_ctx->sig_list->sm_lists[DETECT_SM_LIST_UMATCH]; DetectContentData *ud = sm->ctx; - if (sm != NULL && sm->type == DETECT_URICONTENT) { + if (sm->type == DETECT_URICONTENT) { if (ud->flags & DETECT_CONTENT_FAST_PATTERN && !(ud->flags & DETECT_CONTENT_FAST_PATTERN_ONLY) && ud->flags & DETECT_CONTENT_FAST_PATTERN_CHOP && @@ -4382,16 +4382,14 @@ int DetectFastPatternTest137(void) result = 0; sm = de_ctx->sig_list->sm_lists[DETECT_SM_LIST_HCBDMATCH]; DetectContentData *ud = sm->ctx; - if (sm != NULL) { - if (ud->flags & DETECT_CONTENT_FAST_PATTERN && + if (ud->flags & DETECT_CONTENT_FAST_PATTERN && ud->flags & DETECT_CONTENT_FAST_PATTERN_ONLY && !(ud->flags & DETECT_CONTENT_FAST_PATTERN_CHOP) && ud->fp_chop_offset == 0 && ud->fp_chop_len == 0) { - result = 1; - } else { - result = 0; - } + result = 1; + } else { + result = 0; } end: @@ -4418,16 +4416,14 @@ int DetectFastPatternTest138(void) result = 0; sm = de_ctx->sig_list->sm_lists[DETECT_SM_LIST_HCBDMATCH]; DetectContentData *ud = sm->ctx; - if (sm != NULL) { - if (ud->flags & DETECT_CONTENT_FAST_PATTERN && + if (ud->flags & DETECT_CONTENT_FAST_PATTERN && !(ud->flags & DETECT_CONTENT_FAST_PATTERN_ONLY) && ud->flags & DETECT_CONTENT_FAST_PATTERN_CHOP && ud->fp_chop_offset == 3 && ud->fp_chop_len == 4) { - result = 1; - } else { - result = 0; - } + result = 1; + } else { + result = 0; } end: @@ -5577,16 +5573,14 @@ int DetectFastPatternTest182(void) result = 0; sm = de_ctx->sig_list->sm_lists[DETECT_SM_LIST_HHDMATCH]; DetectContentData *ud = sm->ctx; - if (sm != NULL) { - if (ud->flags & DETECT_CONTENT_FAST_PATTERN && + if (ud->flags & DETECT_CONTENT_FAST_PATTERN && ud->flags & DETECT_CONTENT_FAST_PATTERN_ONLY && !(ud->flags & DETECT_CONTENT_FAST_PATTERN_CHOP) && ud->fp_chop_offset == 0 && ud->fp_chop_len == 0) { - result = 1; - } else { - result = 0; - } + result = 1; + } else { + result = 0; } end: @@ -5613,16 +5607,14 @@ int DetectFastPatternTest183(void) result = 0; sm = de_ctx->sig_list->sm_lists[DETECT_SM_LIST_HHDMATCH]; DetectContentData *ud = sm->ctx; - if (sm != NULL) { - if (ud->flags & DETECT_CONTENT_FAST_PATTERN && + if (ud->flags & DETECT_CONTENT_FAST_PATTERN && !(ud->flags & DETECT_CONTENT_FAST_PATTERN_ONLY) && ud->flags & DETECT_CONTENT_FAST_PATTERN_CHOP && ud->fp_chop_offset == 3 && ud->fp_chop_len == 4) { - result = 1; - } else { - result = 0; - } + result = 1; + } else { + result = 0; } end: @@ -6696,16 +6688,14 @@ int DetectFastPatternTest223(void) result = 0; sm = de_ctx->sig_list->sm_lists[DETECT_SM_LIST_HRHDMATCH]; DetectContentData *ud = sm->ctx; - if (sm != NULL) { - if (ud->flags & DETECT_CONTENT_FAST_PATTERN && + if (ud->flags & DETECT_CONTENT_FAST_PATTERN && ud->flags & DETECT_CONTENT_FAST_PATTERN_ONLY && !(ud->flags & DETECT_CONTENT_FAST_PATTERN_CHOP) && ud->fp_chop_offset == 0 && ud->fp_chop_len == 0) { - result = 1; - } else { - result = 0; - } + result = 1; + } else { + result = 0; } end: @@ -6732,16 +6722,14 @@ int DetectFastPatternTest224(void) result = 0; sm = de_ctx->sig_list->sm_lists[DETECT_SM_LIST_HRHDMATCH]; DetectContentData *ud = sm->ctx; - if (sm != NULL) { - if (ud->flags & DETECT_CONTENT_FAST_PATTERN && + if (ud->flags & DETECT_CONTENT_FAST_PATTERN && !(ud->flags & DETECT_CONTENT_FAST_PATTERN_ONLY) && ud->flags & DETECT_CONTENT_FAST_PATTERN_CHOP && ud->fp_chop_offset == 3 && ud->fp_chop_len == 4) { - result = 1; - } else { - result = 0; - } + result = 1; + } else { + result = 0; } end: @@ -7819,16 +7807,14 @@ int DetectFastPatternTest264(void) result = 0; sm = de_ctx->sig_list->sm_lists[DETECT_SM_LIST_HMDMATCH]; DetectContentData *ud = sm->ctx; - if (sm != NULL) { - if (ud->flags & DETECT_CONTENT_FAST_PATTERN && + if (ud->flags & DETECT_CONTENT_FAST_PATTERN && ud->flags & DETECT_CONTENT_FAST_PATTERN_ONLY && !(ud->flags & DETECT_CONTENT_FAST_PATTERN_CHOP) && ud->fp_chop_offset == 0 && ud->fp_chop_len == 0) { - result = 1; - } else { - result = 0; - } + result = 1; + } else { + result = 0; } end: @@ -7855,16 +7841,14 @@ int DetectFastPatternTest265(void) result = 0; sm = de_ctx->sig_list->sm_lists[DETECT_SM_LIST_HMDMATCH]; DetectContentData *ud = sm->ctx; - if (sm != NULL) { - if (ud->flags & DETECT_CONTENT_FAST_PATTERN && + if (ud->flags & DETECT_CONTENT_FAST_PATTERN && !(ud->flags & DETECT_CONTENT_FAST_PATTERN_ONLY) && ud->flags & DETECT_CONTENT_FAST_PATTERN_CHOP && ud->fp_chop_offset == 3 && ud->fp_chop_len == 4) { - result = 1; - } else { - result = 0; - } + result = 1; + } else { + result = 0; } end: @@ -8937,16 +8921,14 @@ int DetectFastPatternTest305(void) result = 0; sm = de_ctx->sig_list->sm_lists[DETECT_SM_LIST_HCDMATCH]; DetectContentData *ud = sm->ctx; - if (sm != NULL) { - if (ud->flags & DETECT_CONTENT_FAST_PATTERN && + if (ud->flags & DETECT_CONTENT_FAST_PATTERN && ud->flags & DETECT_CONTENT_FAST_PATTERN_ONLY && !(ud->flags & DETECT_CONTENT_FAST_PATTERN_CHOP) && ud->fp_chop_offset == 0 && ud->fp_chop_len == 0) { - result = 1; - } else { - result = 0; - } + result = 1; + } else { + result = 0; } end: @@ -8973,16 +8955,14 @@ int DetectFastPatternTest306(void) result = 0; sm = de_ctx->sig_list->sm_lists[DETECT_SM_LIST_HCDMATCH]; DetectContentData *ud = sm->ctx; - if (sm != NULL) { - if (ud->flags & DETECT_CONTENT_FAST_PATTERN && + if (ud->flags & DETECT_CONTENT_FAST_PATTERN && !(ud->flags & DETECT_CONTENT_FAST_PATTERN_ONLY) && ud->flags & DETECT_CONTENT_FAST_PATTERN_CHOP && ud->fp_chop_offset == 3 && ud->fp_chop_len == 4) { - result = 1; - } else { - result = 0; - } + result = 1; + } else { + result = 0; } end: @@ -10062,16 +10042,14 @@ int DetectFastPatternTest346(void) result = 0; sm = de_ctx->sig_list->sm_lists[DETECT_SM_LIST_HRUDMATCH]; DetectContentData *ud = sm->ctx; - if (sm != NULL) { - if (ud->flags & DETECT_CONTENT_FAST_PATTERN && + if (ud->flags & DETECT_CONTENT_FAST_PATTERN && ud->flags & DETECT_CONTENT_FAST_PATTERN_ONLY && !(ud->flags & DETECT_CONTENT_FAST_PATTERN_CHOP) && ud->fp_chop_offset == 0 && ud->fp_chop_len == 0) { - result = 1; - } else { - result = 0; - } + result = 1; + } else { + result = 0; } end: @@ -10098,16 +10076,14 @@ int DetectFastPatternTest347(void) result = 0; sm = de_ctx->sig_list->sm_lists[DETECT_SM_LIST_HRUDMATCH]; DetectContentData *ud = sm->ctx; - if (sm != NULL) { - if (ud->flags & DETECT_CONTENT_FAST_PATTERN && + if (ud->flags & DETECT_CONTENT_FAST_PATTERN && !(ud->flags & DETECT_CONTENT_FAST_PATTERN_ONLY) && ud->flags & DETECT_CONTENT_FAST_PATTERN_CHOP && ud->fp_chop_offset == 3 && ud->fp_chop_len == 4) { - result = 1; - } else { - result = 0; - } + result = 1; + } else { + result = 0; } end: diff --git a/src/detect-ipproto.c b/src/detect-ipproto.c index 6f023ed3e0..6ec4c65319 100644 --- a/src/detect-ipproto.c +++ b/src/detect-ipproto.c @@ -268,27 +268,29 @@ static int DetectIPProtoSetup(DetectEngineCtx *de_ctx, Signature *s, char *optst } temp_sm = temp_sm->next; } - DetectIPProtoData *data_temp = temp_sm->ctx; - if (data_temp->proto <= data->proto) { - SCLogError(SC_ERR_INVALID_SIGNATURE, "We can't use a have " - "both gt and lt ipprotos, with the lt being " - "lower than gt value"); - goto error; - /* Updated by AS. Please do not remove this unused code. Need it - * as we redo this code once we solve ipproto multiple uses */ + if (temp_sm != NULL) { + DetectIPProtoData *data_temp = temp_sm->ctx; + if (data_temp->proto <= data->proto) { + SCLogError(SC_ERR_INVALID_SIGNATURE, "We can't use a have " + "both gt and lt ipprotos, with the lt being " + "lower than gt value"); + goto error; + /* Updated by AS. Please do not remove this unused code. Need it + * as we redo this code once we solve ipproto multiple uses */ #if 0 - s->proto.proto[data->proto / 8] |= 0xfe << (data->proto % 8); - for (i = (data->proto / 8) + 1; i < (256 / 8); i++) { - s->proto.proto[i] = 0xff; - } + s->proto.proto[data->proto / 8] |= 0xfe << (data->proto % 8); + for (i = (data->proto / 8) + 1; i < (256 / 8); i++) { + s->proto.proto[i] = 0xff; + } #endif - } else { - for (i = 0; i < (data->proto / 8); i++) { - s->proto.proto[i] = 0; - } - s->proto.proto[data->proto / 8] &= 0xfe << (data->proto % 8); - for (i = (data->proto / 8) + 1; i < (256 / 8); i++) { - s->proto.proto[i] &= 0xff; + } else { + for (i = 0; i < (data->proto / 8); i++) { + s->proto.proto[i] = 0; + } + s->proto.proto[data->proto / 8] &= 0xfe << (data->proto % 8); + for (i = (data->proto / 8) + 1; i < (256 / 8); i++) { + s->proto.proto[i] &= 0xff; + } } } } else if (!lt_set && not_set) { @@ -309,48 +311,50 @@ static int DetectIPProtoSetup(DetectEngineCtx *de_ctx, Signature *s, char *optst } temp_sm = temp_sm->next; } - data_temp = temp_sm->ctx; - if (data_temp->proto <= data->proto) { - /* Updated by AS. Please do not remove this unused code. - * Need it as we redo this code once we solve ipproto - * multiple uses */ - SCLogError(SC_ERR_INVALID_SIGNATURE, "We can't use a have " - "both gt and lt ipprotos, with the lt being " - "lower than gt value"); - goto error; + if (temp_sm != NULL) { + data_temp = temp_sm->ctx; + if (data_temp->proto <= data->proto) { + /* Updated by AS. Please do not remove this unused code. + * Need it as we redo this code once we solve ipproto + * multiple uses */ + SCLogError(SC_ERR_INVALID_SIGNATURE, "We can't use a have " + "both gt and lt ipprotos, with the lt being " + "lower than gt value"); + goto error; #if 0 - s->proto.proto[data->proto / 8] |= 0xfe << (data->proto % 8); - for (i = (data->proto / 8) + 1; i < (256 / 8); i++) { - s->proto.proto[i] = 0xff; - } - temp_sm = s->sm_lists[DETECT_SM_LIST_MATCH]; - uint8_t *not_protos = NULL; - int not_protos_len = 0; - while (temp_sm != NULL) { - if (temp_sm->type == DETECT_IPPROTO && - ((DetectIPProtoData *)temp_sm->ctx)->op == DETECT_IPPROTO_OP_NOT) { - DetectIPProtoData *data_temp = temp_sm->ctx; - not_protos = SCRealloc(not_protos, - (not_protos_len + 1) * sizeof(uint8_t)); - if (not_protos == NULL) - goto error; - not_protos[not_protos_len] = data_temp->proto; - not_protos_len++; + s->proto.proto[data->proto / 8] |= 0xfe << (data->proto % 8); + for (i = (data->proto / 8) + 1; i < (256 / 8); i++) { + s->proto.proto[i] = 0xff; } - temp_sm = temp_sm->next; - } - qsort(not_protos, not_protos_len, sizeof(uint8_t), - DetectIPProtoQSortCompare); - int j = 0; - while (j < not_protos_len) { - if (not_protos[j] < data->proto) { - ; - } else { - s->proto.proto[not_protos[j] / 8] &= ~(1 << (not_protos[j] % 8)); + temp_sm = s->sm_lists[DETECT_SM_LIST_MATCH]; + uint8_t *not_protos = NULL; + int not_protos_len = 0; + while (temp_sm != NULL) { + if (temp_sm->type == DETECT_IPPROTO && + ((DetectIPProtoData *)temp_sm->ctx)->op == DETECT_IPPROTO_OP_NOT) { + DetectIPProtoData *data_temp = temp_sm->ctx; + not_protos = SCRealloc(not_protos, + (not_protos_len + 1) * sizeof(uint8_t)); + if (not_protos == NULL) + goto error; + not_protos[not_protos_len] = data_temp->proto; + not_protos_len++; + } + temp_sm = temp_sm->next; + } + qsort(not_protos, not_protos_len, sizeof(uint8_t), + DetectIPProtoQSortCompare); + int j = 0; + while (j < not_protos_len) { + if (not_protos[j] < data->proto) { + ; + } else { + s->proto.proto[not_protos[j] / 8] &= ~(1 << (not_protos[j] % 8)); + } + j++; } - j++; - } #endif + } } else { for (i = 0; i < (data->proto / 8); i++) { s->proto.proto[i] = 0; @@ -383,28 +387,30 @@ static int DetectIPProtoSetup(DetectEngineCtx *de_ctx, Signature *s, char *optst } temp_sm = temp_sm->next; } - DetectIPProtoData *data_temp = temp_sm->ctx; - if (data_temp->proto >= data->proto) { - /* Updated by AS. Please do not remove this unused code. - * Need it as we redo this code once we solve ipproto - * multiple uses */ - SCLogError(SC_ERR_INVALID_SIGNATURE, "We can't use a have " - "both gt and lt ipprotos, with the lt being " - "lower than gt value"); - goto error; + if (temp_sm != NULL) { + DetectIPProtoData *data_temp = temp_sm->ctx; + if (data_temp->proto >= data->proto) { + /* Updated by AS. Please do not remove this unused code. + * Need it as we redo this code once we solve ipproto + * multiple uses */ + SCLogError(SC_ERR_INVALID_SIGNATURE, "We can't use a have " + "both gt and lt ipprotos, with the lt being " + "lower than gt value"); + goto error; #if 0 - for (i = 0; i < (data->proto / 8); i++) { - s->proto.proto[i] = 0xff; - } - s->proto.proto[data->proto / 8] |= ~(0xff << (data->proto % 8));; + for (i = 0; i < (data->proto / 8); i++) { + s->proto.proto[i] = 0xff; + } + s->proto.proto[data->proto / 8] |= ~(0xff << (data->proto % 8));; #endif - } else { - for (i = 0; i < (data->proto / 8); i++) { - s->proto.proto[i] &= 0xff; - } - s->proto.proto[data->proto / 8] &= ~(0xff << (data->proto % 8)); - for (i = (data->proto / 8) + 1; i < 256 / 8; i++) { - s->proto.proto[i] = 0; + } else { + for (i = 0; i < (data->proto / 8); i++) { + s->proto.proto[i] &= 0xff; + } + s->proto.proto[data->proto / 8] &= ~(0xff << (data->proto % 8)); + for (i = (data->proto / 8) + 1; i < 256 / 8; i++) { + s->proto.proto[i] = 0; + } } } } else if (!gt_set && not_set) { @@ -425,48 +431,50 @@ static int DetectIPProtoSetup(DetectEngineCtx *de_ctx, Signature *s, char *optst } temp_sm = temp_sm->next; } - data_temp = temp_sm->ctx; - if (data_temp->proto >= data->proto) { - /* Updated by AS. Please do not remove this unused code. - * Need it as we redo this code once we solve ipproto - * multiple uses */ - SCLogError(SC_ERR_INVALID_SIGNATURE, "We can't use a have " - "both gt and lt ipprotos, with the lt being " - "lower than gt value"); - goto error; + if (temp_sm != NULL) { + data_temp = temp_sm->ctx; + if (data_temp->proto >= data->proto) { + /* Updated by AS. Please do not remove this unused code. + * Need it as we redo this code once we solve ipproto + * multiple uses */ + SCLogError(SC_ERR_INVALID_SIGNATURE, "We can't use a have " + "both gt and lt ipprotos, with the lt being " + "lower than gt value"); + goto error; #if 0 - for (i = 0; i < (data->proto / 8); i++) { - s->proto.proto[i] = 0xff; - } - s->proto.proto[data->proto / 8] |= ~(0xff << (data->proto % 8)); - temp_sm = s->sm_lists[DETECT_SM_LIST_MATCH]; - uint8_t *not_protos = NULL; - int not_protos_len = 0; - while (temp_sm != NULL) { - if (temp_sm->type == DETECT_IPPROTO && - ((DetectIPProtoData *)temp_sm->ctx)->op == DETECT_IPPROTO_OP_NOT) { - DetectIPProtoData *data_temp = temp_sm->ctx; - not_protos = SCRealloc(not_protos, - (not_protos_len + 1) * sizeof(uint8_t)); - if (not_protos == NULL) - goto error; - not_protos[not_protos_len] = data_temp->proto; - not_protos_len++; + for (i = 0; i < (data->proto / 8); i++) { + s->proto.proto[i] = 0xff; } - temp_sm = temp_sm->next; - } - qsort(not_protos, not_protos_len, sizeof(uint8_t), - DetectIPProtoQSortCompare); - int j = 0; - while (j < not_protos_len) { - if (not_protos[j] < data->proto) { - s->proto.proto[not_protos[j] / 8] &= ~(1 << (not_protos[j] % 8)); - } else { - ; + s->proto.proto[data->proto / 8] |= ~(0xff << (data->proto % 8)); + temp_sm = s->sm_lists[DETECT_SM_LIST_MATCH]; + uint8_t *not_protos = NULL; + int not_protos_len = 0; + while (temp_sm != NULL) { + if (temp_sm->type == DETECT_IPPROTO && + ((DetectIPProtoData *)temp_sm->ctx)->op == DETECT_IPPROTO_OP_NOT) { + DetectIPProtoData *data_temp = temp_sm->ctx; + not_protos = SCRealloc(not_protos, + (not_protos_len + 1) * sizeof(uint8_t)); + if (not_protos == NULL) + goto error; + not_protos[not_protos_len] = data_temp->proto; + not_protos_len++; + } + temp_sm = temp_sm->next; + } + qsort(not_protos, not_protos_len, sizeof(uint8_t), + DetectIPProtoQSortCompare); + int j = 0; + while (j < not_protos_len) { + if (not_protos[j] < data->proto) { + s->proto.proto[not_protos[j] / 8] &= ~(1 << (not_protos[j] % 8)); + } else { + ; + } + j++; } - j++; - } #endif + } } else { for (i = 0; i < (data->proto / 8); i++) { s->proto.proto[i] &= 0xFF; diff --git a/src/util-pool.c b/src/util-pool.c index b42bf30624..f325cdcde7 100644 --- a/src/util-pool.c +++ b/src/util-pool.c @@ -215,7 +215,8 @@ void PoolPrintSaturation(Pool *p) { */ void *PoolTestAlloc(void *allocdata) { - return SCMalloc(10); + void *ptr = SCMalloc(10); + return ptr; } void *PoolTestAllocArg(void *allocdata) { size_t len = strlen((char *)allocdata) + 1;