diff --git a/src/app-layer-htp.c b/src/app-layer-htp.c index c53c12bc2b..8fbd123e3c 100644 --- a/src/app-layer-htp.c +++ b/src/app-layer-htp.c @@ -256,8 +256,8 @@ static int HTPHandleRequestData(Flow *f, void *htp_state, goto error; } - if (cfgnode != NULL) { - htp = SC_RADIX_NODE_USERDATA(cfgnode, HTPCfgRec)->cfg; + if (cfgnode != NULL && cfgnode->prefix != NULL) { + htp = ((HTPCfgRec*)(cfgnode->prefix->user_data_result))->cfg; SCLogDebug("LIBHTP using config: %p", htp); } else { SCLogDebug("Using default HTP config: %p", htp); @@ -1680,7 +1680,9 @@ libhtp:\n\ addr = "192.168.10.42"; if (inet_pton(AF_INET, addr, buf) == 1) { cfgnode = SCRadixFindKeyIPV4BestMatch(buf, cfgtree); - htp = SC_RADIX_NODE_USERDATA(cfgnode, HTPCfgRec)->cfg; + if (cfgnode != NULL && cfgnode->prefix != NULL) { + htp = ((HTPCfgRec*)(cfgnode->prefix->user_data_result))->cfg; + } if (htp == NULL) { printf("Could not get config for: %s\n", addr); goto end; @@ -1694,7 +1696,9 @@ libhtp:\n\ addr = "::1"; if (inet_pton(AF_INET6, addr, buf) == 1) { cfgnode = SCRadixFindKeyIPV6BestMatch(buf, cfgtree); - htp = SC_RADIX_NODE_USERDATA(cfgnode, HTPCfgRec)->cfg; + if (cfgnode != NULL && cfgnode->prefix != NULL) { + htp = ((HTPCfgRec*)(cfgnode->prefix->user_data_result))->cfg; + } if (htp == NULL) { printf("Could not get config for: %s\n", addr); goto end; @@ -1765,7 +1769,9 @@ libhtp:\n\ SCRadixNode *cfgnode = NULL; htp_cfg_t *htp = cfglist.cfg; cfgnode = SCRadixFindKeyIPV4BestMatch((uint8_t *)GET_IPV4_DST_ADDR_PTR(&f), cfgtree); - htp = SC_RADIX_NODE_USERDATA(cfgnode, HTPCfgRec)->cfg; + if (cfgnode != NULL && cfgnode->prefix != NULL) { + htp = ((HTPCfgRec*)(cfgnode->prefix->user_data_result))->cfg; + } if (htp == NULL) { printf("Could not get config for: %s\n", addr); goto end; diff --git a/src/counters.c b/src/counters.c index 665255782f..f2be763615 100644 --- a/src/counters.c +++ b/src/counters.c @@ -709,28 +709,33 @@ static int SCPerfOutputCounterFileIface() for (u = 0; u < TVT_MAX; u++) { tv = tv_root[u]; + if (pc_heads == NULL || pc_heads[u] == NULL) + continue; + while (tv != NULL) { SCMutexLock(&tv->sc_perf_pctx.m); pc = tv->sc_perf_pctx.head; while (pc != NULL) { - if (pc->disp == 0) { + if (pc->disp == 0 || pc->value == NULL) { pc = pc->next; continue; } switch (pc->value->type) { case SC_PERF_TYPE_UINT64: - SCPerfOutputCalculateCounterValue(pc_heads[u], &ui64_temp); - fprintf(sc_perf_op_ctx->fp, "%-25s | %-25s | %-" PRIu64 "\n", - pc->name->cname, pc->name->tm_name, ui64_temp); - + SCPerfOutputCalculateCounterValue(pc_heads[u], + &ui64_temp); + fprintf(sc_perf_op_ctx->fp, "%-25s | %-25s | " + "%-" PRIu64 "\n", pc->name->cname, + pc->name->tm_name, ui64_temp); break; case SC_PERF_TYPE_DOUBLE: - SCPerfOutputCalculateCounterValue(pc_heads[u], &double_temp); - fprintf(sc_perf_op_ctx->fp, "%-25s | %-25s | %-lf\n", - pc->name->cname, pc->name->tm_name, double_temp); - + SCPerfOutputCalculateCounterValue(pc_heads[u], + &double_temp); + fprintf(sc_perf_op_ctx->fp, "%-25s | %-25s |" + " %-lf\n", pc->name->cname, + pc->name->tm_name, double_temp); break; } @@ -767,6 +772,8 @@ static int SCPerfOutputCounterFileIface() while(flag) { ui64_result = 0; double_result = 0; + if (pc_heads[0] == NULL) + break; pc = pc_heads[0]; for (u = 0; u < pctmi->size; u++) { @@ -786,11 +793,12 @@ static int SCPerfOutputCounterFileIface() pc_heads[u] = pc_heads[u]->next; if (pc_heads[u] == NULL || - strcmp(pctmi->tm_name, pc_heads[0]->name->tm_name)) + (pc_heads[0] != NULL && + strcmp(pctmi->tm_name, pc_heads[0]->name->tm_name))) flag = 0; } - if (pc->disp == 0) + if (pc->disp == 0 || pc->value == NULL) continue; switch (pc->value->type) { diff --git a/src/detect-bytetest.c b/src/detect-bytetest.c index 1e0a369bf0..e038c4e27f 100644 --- a/src/detect-bytetest.c +++ b/src/detect-bytetest.c @@ -396,24 +396,26 @@ DetectBytetestData *DetectBytetestParse(char *optstr) /* Operator is next two args: neg + op */ data->op = 0; - if (*args[1] == '!') { + if (args[1] != NULL && *args[1] == '!') { data->flags |= DETECT_BYTETEST_NEGOP; } - if ((strcmp("=", args[2]) == 0) || ((data->flags & DETECT_BYTETEST_NEGOP) - && strcmp("", args[2]) == 0)) - { - data->op |= DETECT_BYTETEST_OP_EQ; - } else if (strcmp("<", args[2]) == 0) { - data->op |= DETECT_BYTETEST_OP_LT; - } else if (strcmp(">", args[2]) == 0) { - data->op |= DETECT_BYTETEST_OP_GT; - } else if (strcmp("&", args[2]) == 0) { - data->op |= DETECT_BYTETEST_OP_AND; - } else if (strcmp("^", args[2]) == 0) { - data->op |= DETECT_BYTETEST_OP_OR; - } else { - SCLogError(SC_ERR_INVALID_OPERATOR, "Invalid operator"); - goto error; + + if (args[2] != NULL) { + if ((strcmp("=", args[2]) == 0) || ((data->flags & DETECT_BYTETEST_NEGOP) + && strcmp("", args[2]) == 0)) { + data->op |= DETECT_BYTETEST_OP_EQ; + } else if (strcmp("<", args[2]) == 0) { + data->op |= DETECT_BYTETEST_OP_LT; + } else if (strcmp(">", args[2]) == 0) { + data->op |= DETECT_BYTETEST_OP_GT; + } else if (strcmp("&", args[2]) == 0) { + data->op |= DETECT_BYTETEST_OP_AND; + } else if (strcmp("^", args[2]) == 0) { + data->op |= DETECT_BYTETEST_OP_OR; + } else { + SCLogError(SC_ERR_INVALID_OPERATOR, "Invalid operator"); + goto error; + } } /* Value */ @@ -432,25 +434,28 @@ DetectBytetestData *DetectBytetestParse(char *optstr) /* The remaining options are flags. */ /** \todo Error on dups? */ for (i = 5; i < (ret - 1); i++) { - if (strcmp("relative", args[i]) == 0) { - data->flags |= DETECT_BYTETEST_RELATIVE; - } else if (strcasecmp("string", args[i]) == 0) { - data->flags |= DETECT_BYTETEST_STRING; - } else if (strcasecmp("dec", args[i]) == 0) { - data->base |= DETECT_BYTETEST_BASE_DEC; - } else if (strcasecmp("hex", args[i]) == 0) { - data->base |= DETECT_BYTETEST_BASE_HEX; - } else if (strcasecmp("oct", args[i]) == 0) { - data->base |= DETECT_BYTETEST_BASE_OCT; - } else if (strcasecmp("big", args[i]) == 0) { - if (data->flags & DETECT_BYTETEST_LITTLE) { - data->flags ^= DETECT_BYTETEST_LITTLE; + if (args[i] != NULL) { + if (strcmp("relative", args[i]) == 0) { + data->flags |= DETECT_BYTETEST_RELATIVE; + } else if (strcasecmp("string", args[i]) == 0) { + data->flags |= DETECT_BYTETEST_STRING; + } else if (strcasecmp("dec", args[i]) == 0) { + data->base |= DETECT_BYTETEST_BASE_DEC; + } else if (strcasecmp("hex", args[i]) == 0) { + data->base |= DETECT_BYTETEST_BASE_HEX; + } else if (strcasecmp("oct", args[i]) == 0) { + data->base |= DETECT_BYTETEST_BASE_OCT; + } else if (strcasecmp("big", args[i]) == 0) { + if (data->flags & DETECT_BYTETEST_LITTLE) { + data->flags ^= DETECT_BYTETEST_LITTLE; + } + } else if (strcasecmp("little", args[i]) == 0) { + data->flags |= DETECT_BYTETEST_LITTLE; + } else { + SCLogError(SC_ERR_UNKNOWN_VALUE, "Unknown value: \"%s\"", + args[i]); + goto error; } - } else if (strcasecmp("little", args[i]) == 0) { - data->flags |= DETECT_BYTETEST_LITTLE; - } else { - SCLogError(SC_ERR_UNKNOWN_VALUE, "Unknown value: \"%s\"", args[i]); - goto error; } } diff --git a/src/detect-content.c b/src/detect-content.c index c01f89d511..834842ec85 100644 --- a/src/detect-content.c +++ b/src/detect-content.c @@ -1157,7 +1157,7 @@ static int SigTestPositiveTestContent(char *rule, uint8_t *buf) uint16_t buflen = strlen((char *)buf); Packet p; ThreadVars th_v; - DetectEngineThreadCtx *det_ctx; + DetectEngineThreadCtx *det_ctx = NULL; int result = 0; memset(&th_v, 0, sizeof(th_v)); diff --git a/src/detect-dce-iface.c b/src/detect-dce-iface.c index 07530e5d12..c6233ea0d3 100644 --- a/src/detect-dce-iface.c +++ b/src/detect-dce-iface.c @@ -390,9 +390,11 @@ static int DetectDceIfaceTestParse01(void) } } - result &= (did->version == 0); - result &= (did->op == 0); - result &= (did->any_frag == 0); + if (did != NULL) { + result &= (did->version == 0); + result &= (did->op == 0); + result &= (did->any_frag == 0); + } SigFree(s); return result; @@ -422,9 +424,11 @@ static int DetectDceIfaceTestParse02(void) } } - result &= (did->version == 1); - result &= (did->op == DETECT_DCE_IFACE_OP_GT); - result &= (did->any_frag == 0); + if (did != NULL) { + result &= (did->version == 1); + result &= (did->op == DETECT_DCE_IFACE_OP_GT); + result &= (did->any_frag == 0); + } SigFree(s); return result; @@ -454,9 +458,11 @@ static int DetectDceIfaceTestParse03(void) } } - result &= (did->version == 10); - result &= (did->op == DETECT_DCE_IFACE_OP_LT); - result &= (did->any_frag == 0); + if (did != NULL) { + result &= (did->version == 10); + result &= (did->op == DETECT_DCE_IFACE_OP_LT); + result &= (did->any_frag == 0); + } SigFree(s); return result; @@ -486,9 +492,11 @@ static int DetectDceIfaceTestParse04(void) } } - result &= (did->version == 10); - result &= (did->op == DETECT_DCE_IFACE_OP_NE); - result &= (did->any_frag == 0); + if (did != NULL) { + result &= (did->version == 10); + result &= (did->op == DETECT_DCE_IFACE_OP_NE); + result &= (did->any_frag == 0); + } SigFree(s); return result; @@ -518,9 +526,11 @@ static int DetectDceIfaceTestParse05(void) } } - result &= (did->version == 10); - result &= (did->op == DETECT_DCE_IFACE_OP_EQ); - result &= (did->any_frag == 0); + if (did != NULL) { + result &= (did->version == 10); + result &= (did->op == DETECT_DCE_IFACE_OP_EQ); + result &= (did->any_frag == 0); + } SigFree(s); return result; @@ -550,10 +560,11 @@ static int DetectDceIfaceTestParse06(void) } } - result &= (did->version == 0); - result &= (did->op == 0); - result &= (did->any_frag == 1); - + if (did != NULL) { + result &= (did->version == 0); + result &= (did->op == 0); + result &= (did->any_frag == 1); + } SigFree(s); return result; } @@ -582,9 +593,11 @@ static int DetectDceIfaceTestParse07(void) } } - result &= (did->version == 1); - result &= (did->op == DETECT_DCE_IFACE_OP_GT); - result &= (did->any_frag == 1); + if (did != NULL) { + result &= (did->version == 1); + result &= (did->op == DETECT_DCE_IFACE_OP_GT); + result &= (did->any_frag == 1); + } SigFree(s); return result; @@ -614,9 +627,11 @@ static int DetectDceIfaceTestParse08(void) } } - result &= (did->version == 1); - result &= (did->op == DETECT_DCE_IFACE_OP_LT); - result &= (did->any_frag == 1); + if (did != NULL) { + result &= (did->version == 1); + result &= (did->op == DETECT_DCE_IFACE_OP_LT); + result &= (did->any_frag == 1); + } SigFree(s); return result; @@ -646,9 +661,11 @@ static int DetectDceIfaceTestParse09(void) } } - result &= (did->version == 1); - result &= (did->op == DETECT_DCE_IFACE_OP_EQ); - result &= (did->any_frag == 1); + if (did != NULL) { + result &= (did->version == 1); + result &= (did->op == DETECT_DCE_IFACE_OP_EQ); + result &= (did->any_frag == 1); + } SigFree(s); return result; @@ -678,9 +695,11 @@ static int DetectDceIfaceTestParse10(void) } } - result &= (did->version == 1); - result &= (did->op == DETECT_DCE_IFACE_OP_NE); - result &= (did->any_frag == 1); + if (did != NULL) { + result &= (did->version == 1); + result &= (did->op == DETECT_DCE_IFACE_OP_NE); + result &= (did->any_frag == 1); + } SigFree(s); return result; diff --git a/src/detect-detection-filter.c b/src/detect-detection-filter.c index e25e93afec..19496935f4 100644 --- a/src/detect-detection-filter.c +++ b/src/detect-detection-filter.c @@ -151,11 +151,17 @@ DetectThresholdData *DetectDetectionFilterParse (char *rawstr) { seconds_pos = i+1; } - if (ByteExtractStringUint32(&df->count, 10, strlen(args[count_pos]), args[count_pos]) <= 0) { + if (args[count_pos] != NULL && + ByteExtractStringUint32(&df->count, 10, strlen(args[count_pos]), + args[count_pos]) <= 0) + { goto error; } - if (ByteExtractStringUint32(&df->seconds, 10, strlen(args[seconds_pos]), args[seconds_pos]) <= 0) { + if (args[seconds_pos] != NULL && + ByteExtractStringUint32(&df->seconds, 10, strlen(args[seconds_pos]), + args[seconds_pos]) <= 0) + { goto error; } diff --git a/src/detect-engine-address-ipv4.c b/src/detect-engine-address-ipv4.c index 3d7ffc5fad..28883a3331 100644 --- a/src/detect-engine-address-ipv4.c +++ b/src/detect-engine-address-ipv4.c @@ -1368,9 +1368,12 @@ static int DetectAddressIPv4CutNot08(void) goto error; result &= (a->ip2[0] = in.s_addr); - result &= (b != NULL); - if (result == 0) + if (b == NULL) { + result = 0; goto error; + } else { + result &= 1; + } if (inet_pton(AF_INET, "1.2.3.5", &in) < 0) goto error; result &= (b->ip[0] == in.s_addr); @@ -1417,9 +1420,12 @@ static int DetectAddressIPv4CutNot09(void) goto error; result &= (a->ip2[0] = in.s_addr); - result &= (b != NULL); - if (result == 0) + if (b == NULL) { + result = 0; goto error; + } else { + result &= 1; + } if (inet_pton(AF_INET, "192.168.1.3", &in) < 0) goto error; result &= (b->ip[0] == in.s_addr); diff --git a/src/detect-engine-sigorder.c b/src/detect-engine-sigorder.c index 48ca5e924e..5434273d16 100644 --- a/src/detect-engine-sigorder.c +++ b/src/detect-engine-sigorder.c @@ -296,8 +296,10 @@ 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 != sw->min) { + while (min != NULL && min != sw->min) { if (min->sig->action != sw->sig->action) break; @@ -306,8 +308,10 @@ 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 != sw->max) { + while (max != NULL && max != sw->max) { if (max->sig->action != sw->sig->action) break; @@ -346,7 +350,7 @@ static void SCSigOrderByFlowbits(DetectEngineCtx *de_ctx, else min = min->next; - while (min != max) { + while (min != NULL && min != max) { prev = min; /* the sorting logic */ if ( *((int *)(sw->user[SC_RADIX_USER_DATA_FLOWBITS])) <= @@ -397,8 +401,10 @@ 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 != sw->min) { + while (min != NULL && min != sw->min) { if ( *((int *)(sw->user[SC_RADIX_USER_DATA_FLOWBITS])) != *((int *)(min->user[SC_RADIX_USER_DATA_FLOWBITS])) ) break; @@ -408,8 +414,10 @@ 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 != sw->max) { + while (max!= NULL && max != sw->max) { if ( *((int *)(sw->user[SC_RADIX_USER_DATA_FLOWBITS])) != *((int *)(max->user[SC_RADIX_USER_DATA_FLOWBITS])) ) break; @@ -501,8 +509,10 @@ 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 != sw->min) { + while (min != NULL && min != sw->min) { if ( *((int *)(sw->user[SC_RADIX_USER_DATA_FLOWVAR])) != *((int *)(min->user[SC_RADIX_USER_DATA_FLOWVAR])) ) break; @@ -512,8 +522,10 @@ 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 != sw->max) { + while (max != NULL && max != sw->max) { if ( *((int *)(sw->user[SC_RADIX_USER_DATA_FLOWVAR])) != *((int *)(max->user[SC_RADIX_USER_DATA_FLOWVAR])) ) break; @@ -552,7 +564,7 @@ static void SCSigOrderByPktvar(DetectEngineCtx *de_ctx, min = de_ctx->sc_sig_sig_wrapper; else min = min->next; - while (min != max) { + while (min != NULL && min != max) { prev = min; /* the sorting logic */ if ( *((int *)(sw->user[SC_RADIX_USER_DATA_PKTVAR])) <= @@ -603,8 +615,11 @@ 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 != sw->min) { + while (min != NULL && min != sw->min) { if ( *((int *)(sw->user[SC_RADIX_USER_DATA_PKTVAR])) != *((int *)(min->user[SC_RADIX_USER_DATA_PKTVAR])) ) break; @@ -614,8 +629,10 @@ 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 != sw->max) { + while (max != NULL && max != sw->max) { if ( *((int *)(sw->user[SC_RADIX_USER_DATA_PKTVAR])) != *((int *)(max->user[SC_RADIX_USER_DATA_PKTVAR])) ) break; @@ -705,8 +722,11 @@ 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 != sw->min) { + while (min != NULL && min != sw->min) { if (min->sig->prio != sw->sig->prio) break; @@ -715,8 +735,11 @@ 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 != sw->max) { + while (max != NULL && max != sw->max) { if (max->sig->prio != sw->sig->prio) break; diff --git a/src/detect-fast-pattern.c b/src/detect-fast-pattern.c index d690013bc5..8a6ec8f4d7 100644 --- a/src/detect-fast-pattern.c +++ b/src/detect-fast-pattern.c @@ -239,7 +239,7 @@ int DetectFastPatternTest05(void) uint16_t buflen = strlen((char *)buf); Packet p; ThreadVars th_v; - DetectEngineThreadCtx *det_ctx; + DetectEngineThreadCtx *det_ctx = NULL; int result = 0; memset(&th_v, 0, sizeof(th_v)); @@ -295,7 +295,7 @@ int DetectFastPatternTest06(void) uint16_t buflen = strlen((char *)buf); Packet p; ThreadVars th_v; - DetectEngineThreadCtx *det_ctx; + DetectEngineThreadCtx *det_ctx = NULL; int result = 0; memset(&th_v, 0, sizeof(th_v)); @@ -350,7 +350,7 @@ int DetectFastPatternTest07(void) uint16_t buflen = strlen((char *)buf); Packet p; ThreadVars th_v; - DetectEngineThreadCtx *det_ctx; + DetectEngineThreadCtx *det_ctx = NULL; int result = 0; memset(&th_v, 0, sizeof(th_v)); @@ -405,7 +405,7 @@ int DetectFastPatternTest08(void) uint16_t buflen = strlen((char *)buf); Packet p; ThreadVars th_v; - DetectEngineThreadCtx *det_ctx; + DetectEngineThreadCtx *det_ctx = NULL; int result = 0; memset(&th_v, 0, sizeof(th_v)); @@ -460,7 +460,7 @@ int DetectFastPatternTest09(void) uint16_t buflen = strlen((char *)buf); Packet p; ThreadVars th_v; - DetectEngineThreadCtx *det_ctx; + DetectEngineThreadCtx *det_ctx = NULL; int result = 0; memset(&th_v, 0, sizeof(th_v)); @@ -516,7 +516,7 @@ int DetectFastPatternTest10(void) uint16_t buflen = strlen((char *)buf); Packet p; ThreadVars th_v; - DetectEngineThreadCtx *det_ctx; + DetectEngineThreadCtx *det_ctx = NULL; int result = 0; memset(&th_v, 0, sizeof(th_v)); @@ -572,7 +572,7 @@ int DetectFastPatternTest11(void) uint16_t buflen = strlen((char *)buf); Packet p; ThreadVars th_v; - DetectEngineThreadCtx *det_ctx; + DetectEngineThreadCtx *det_ctx = NULL; int result = 0; memset(&th_v, 0, sizeof(th_v)); @@ -628,7 +628,7 @@ int DetectFastPatternTest12(void) uint16_t buflen = strlen((char *)buf); Packet p; ThreadVars th_v; - DetectEngineThreadCtx *det_ctx; + DetectEngineThreadCtx *det_ctx = NULL; int result = 0; memset(&th_v, 0, sizeof(th_v)); @@ -685,7 +685,7 @@ int DetectFastPatternTest13(void) uint16_t buflen = strlen((char *)buf); Packet p; ThreadVars th_v; - DetectEngineThreadCtx *det_ctx; + DetectEngineThreadCtx *det_ctx = NULL; int result = 0; memset(&th_v, 0, sizeof(th_v)); @@ -740,7 +740,7 @@ int DetectFastPatternTest14(void) uint16_t buflen = strlen((char *)buf); Packet p; ThreadVars th_v; - DetectEngineThreadCtx *det_ctx; + DetectEngineThreadCtx *det_ctx = NULL; int alertcnt = 0; int result = 0; diff --git a/src/detect-ftpbounce.c b/src/detect-ftpbounce.c index 59ae710101..d059b207fc 100644 --- a/src/detect-ftpbounce.c +++ b/src/detect-ftpbounce.c @@ -309,7 +309,7 @@ static int DetectFtpbounceTestALMatch02(void) { Packet p; Signature *s = NULL; ThreadVars th_v; - DetectEngineThreadCtx *det_ctx; + DetectEngineThreadCtx *det_ctx = NULL; memset(&th_v, 0, sizeof(th_v)); memset(&p, 0, sizeof(p)); @@ -431,7 +431,7 @@ static int DetectFtpbounceTestALMatch03(void) { Packet p; Signature *s = NULL; ThreadVars th_v; - DetectEngineThreadCtx *det_ctx; + DetectEngineThreadCtx *det_ctx = NULL; memset(&th_v, 0, sizeof(th_v)); memset(&p, 0, sizeof(p)); diff --git a/src/detect-http-client-body.c b/src/detect-http-client-body.c index bfb27e1229..0b17518d04 100644 --- a/src/detect-http-client-body.c +++ b/src/detect-http-client-body.c @@ -267,8 +267,11 @@ static int DetectHttpClientBodyTest01(void) de_ctx->sig_list = SigInit(de_ctx, "alert tcp any any -> any any " "(msg:\"Testing http_client_body\"; " "content:one; http_client_body; sid:1;)"); - if (de_ctx->sig_list != NULL) + if (de_ctx->sig_list != NULL) { result = 1; + } else { + goto end; + } sm = de_ctx->sig_list->match; if (sm != NULL) { diff --git a/src/detect-http-cookie.c b/src/detect-http-cookie.c index 1f8fdfc1f7..233302aceb 100644 --- a/src/detect-http-cookie.c +++ b/src/detect-http-cookie.c @@ -455,7 +455,7 @@ static int DetectHttpCookieSigTest01(void) { Packet p; Signature *s = NULL; ThreadVars th_v; - DetectEngineThreadCtx *det_ctx; + DetectEngineThreadCtx *det_ctx = NULL; HtpState *http_state = NULL; memset(&th_v, 0, sizeof(th_v)); @@ -531,13 +531,12 @@ static int DetectHttpCookieSigTest01(void) { } result = 1; + if (de_ctx != NULL) DetectEngineCtxFree(de_ctx); end: if (http_state != NULL) HTPStateFree(http_state); if (de_ctx != NULL) SigGroupCleanup(de_ctx); - if (de_ctx != NULL) SigCleanSignatures(de_ctx); if (det_ctx != NULL) DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx); - if (de_ctx != NULL) DetectEngineCtxFree(de_ctx); StreamL7DataPtrFree(&ssn); StreamTcpFreeConfig(TRUE); @@ -554,7 +553,7 @@ static int DetectHttpCookieSigTest02(void) { Packet p; Signature *s = NULL; ThreadVars th_v; - DetectEngineThreadCtx *det_ctx; + DetectEngineThreadCtx *det_ctx = NULL; HtpState *http_state = NULL; memset(&th_v, 0, sizeof(th_v)); @@ -618,13 +617,12 @@ static int DetectHttpCookieSigTest02(void) { } result = 1; + end: if (http_state != NULL) HTPStateFree(http_state); if (de_ctx != NULL) SigGroupCleanup(de_ctx); - if (de_ctx != NULL) SigCleanSignatures(de_ctx); if (de_ctx != NULL) DetectEngineCtxFree(de_ctx); - StreamL7DataPtrFree(&ssn); StreamTcpFreeConfig(TRUE); return result; diff --git a/src/detect-icmp-id.c b/src/detect-icmp-id.c index ef4e619baa..466bca7382 100644 --- a/src/detect-icmp-id.c +++ b/src/detect-icmp-id.c @@ -151,7 +151,7 @@ DetectIcmpIdData *DetectIcmpIdParse (char *icmpidstr) { } iid->id = 0; - if (strlen(substr[0]) != 0) { + if (substr[0]!= NULL && strlen(substr[0]) != 0) { if (substr[2] == NULL) { SCLogError(SC_ERR_INVALID_ARGUMENT, "Missing close quote in input"); goto error; diff --git a/src/detect-icmp-seq.c b/src/detect-icmp-seq.c index 87bbf9a31b..e8983abf82 100644 --- a/src/detect-icmp-seq.c +++ b/src/detect-icmp-seq.c @@ -149,7 +149,7 @@ DetectIcmpSeqData *DetectIcmpSeqParse (char *icmpseqstr) { iseq->seq = 0; - if (strlen(substr[0]) != 0) { + if (substr[0] != NULL && strlen(substr[0]) != 0) { if (substr[2] == NULL) { SCLogError(SC_ERR_MISSING_QUOTE,"Missing quote in input"); goto error; diff --git a/src/detect-icode.c b/src/detect-icode.c index 19c90a6953..1f9a1cf652 100644 --- a/src/detect-icode.c +++ b/src/detect-icode.c @@ -152,7 +152,7 @@ DetectICodeData *DetectICodeParse(char *icodestr) { icd->mode = 0; /* we have either "<" or ">" */ - if (strlen(args[0]) != 0) { + if (args[0] != NULL && strlen(args[0]) != 0) { /* we have a third part ("<> y"), therefore it's invalid */ if (args[2] != NULL) { SCLogError(SC_ERR_INVALID_VALUE, "icode: invalid value"); diff --git a/src/detect-itype.c b/src/detect-itype.c index ff8057b918..1396b2a348 100644 --- a/src/detect-itype.c +++ b/src/detect-itype.c @@ -152,7 +152,7 @@ DetectITypeData *DetectITypeParse(char *itypestr) { itd->mode = 0; /* we have either "<" or ">" */ - if (strlen(args[0]) != 0) { + if (args[0] != NULL && strlen(args[0]) != 0) { /* we have a third part ("<> y"), therefore it's invalid */ if (args[2] != NULL) { SCLogError(SC_ERR_INVALID_VALUE, "itype: invalid value"); diff --git a/src/detect-parse.c b/src/detect-parse.c index 66d0757677..f09c9df793 100644 --- a/src/detect-parse.c +++ b/src/detect-parse.c @@ -231,7 +231,8 @@ void SigMatchReplaceContent(Signature *s, SigMatch *old, SigMatch *new) { } /* move over the idx */ - new->idx = pm->idx; + if (pm != NULL) + new->idx = pm->idx; } /** @@ -811,6 +812,8 @@ Signature *SigInit(DetectEngineCtx *de_ctx, char *sigstr) { for (sm = sig->pmatch; sm != NULL; sm = sm->next) { if (sm->type == DETECT_CONTENT) { DetectContentData *cd = (DetectContentData *)sm->ctx; + if (cd == NULL) + continue; if (sig->mpm_content_maxlen == 0) sig->mpm_content_maxlen = cd->content_len; @@ -822,6 +825,9 @@ Signature *SigInit(DetectEngineCtx *de_ctx, char *sigstr) { for (sm = sig->umatch; sm != NULL; sm = sm->next) { if (sm->type == DETECT_URICONTENT) { DetectUricontentData *ud = (DetectUricontentData *)sm->ctx; + if (ud == NULL) + continue; + if (sig->mpm_uricontent_maxlen == 0) sig->mpm_uricontent_maxlen = ud->uricontent_len; if (sig->mpm_uricontent_maxlen < ud->uricontent_len) @@ -928,6 +934,8 @@ Signature *SigInitReal(DetectEngineCtx *de_ctx, char *sigstr) { for (sm = sig->pmatch; sm != NULL; sm = sm->next) { if (sm->type == DETECT_CONTENT) { DetectContentData *cd = (DetectContentData *)sm->ctx; + if (cd == NULL) + continue; if (sig->mpm_content_maxlen == 0) sig->mpm_content_maxlen = cd->content_len; @@ -939,6 +947,8 @@ Signature *SigInitReal(DetectEngineCtx *de_ctx, char *sigstr) { for (sm = sig->umatch; sm != NULL; sm = sm->next) { if (sm->type == DETECT_URICONTENT) { DetectUricontentData *ud = (DetectUricontentData *)sm->ctx; + if (ud == NULL) + continue; if (sig->mpm_uricontent_maxlen == 0) sig->mpm_uricontent_maxlen = ud->uricontent_len; if (sig->mpm_uricontent_maxlen < ud->uricontent_len) @@ -971,6 +981,8 @@ Signature *SigInitReal(DetectEngineCtx *de_ctx, char *sigstr) { for (sm = sig->next->pmatch; sm != NULL; sm = sm->next) { if (sm->type == DETECT_CONTENT) { DetectContentData *cd = (DetectContentData *)sm->ctx; + if (cd == NULL) + continue; if (sig->next->mpm_content_maxlen == 0) sig->next->mpm_content_maxlen = cd->content_len; @@ -981,6 +993,8 @@ Signature *SigInitReal(DetectEngineCtx *de_ctx, char *sigstr) { for (sm = sig->next->umatch; sm != NULL; sm = sm->next) { if (sm->type == DETECT_URICONTENT) { DetectUricontentData *ud = (DetectUricontentData *)sm->ctx; + if (ud == NULL) + continue; if (sig->next->mpm_uricontent_maxlen == 0) sig->next->mpm_uricontent_maxlen = ud->uricontent_len; if (sig->next->mpm_uricontent_maxlen < ud->uricontent_len) @@ -1563,8 +1577,8 @@ int SigTestBidirec03 (void) { uint32_t results[3] = {1, 1, 1}; result = UTHCheckPacketMatchResults(p, sids, results, 1); -end: if (p != NULL) SCFree(p); +end: if (de_ctx != NULL) { SigCleanSignatures(de_ctx); SigGroupCleanup(de_ctx); diff --git a/src/detect-priority.c b/src/detect-priority.c index b74a5ebe4e..fb477f7612 100644 --- a/src/detect-priority.c +++ b/src/detect-priority.c @@ -119,40 +119,52 @@ int DetectPriorityTest02() sig = SigInit(de_ctx, "alert tcp any any -> any any " "(msg:\"Priority test\"; priority:1; sid:1;)"); de_ctx->sig_list = last = sig; - result = (sig != NULL); - result &= (sig->prio == 1); + if (sig == NULL) { + result = 0; + } else { + result = 1; + result &= (sig->prio == 1); + } sig = SigInit(de_ctx, "alert tcp any any -> any any " "(msg:\"Priority test\"; priority:boo; sid:1;)"); - last->next = sig; + if (last != NULL) + last->next = sig; result &= (sig == NULL); sig = SigInit(de_ctx, "alert tcp any any -> any any " "(msg:\"Priority test\"; priority:10boo; sid:1;)"); - last->next = sig; + if (last != NULL) + last->next = sig; result &= (sig == NULL); sig = SigInit(de_ctx, "alert tcp any any -> any any " "(msg:\"Priority test\"; priority:b10oo; sid:1;)"); - last->next = sig; + if (last != NULL) + last->next = sig; result &= (sig == NULL); sig = SigInit(de_ctx, "alert tcp any any -> any any " "(msg:\"Priority test\"; priority:boo10; sid:1;)"); - last->next = sig; + if (last != NULL) + last->next = sig; result &= (sig == NULL); sig = SigInit(de_ctx, "alert tcp any any -> any any " "(msg:\"Priority test\"; priority:-1; sid:1;)"); - last->next = sig; + if (last != NULL) + last->next = sig; result &= (sig == NULL); sig = SigInit(de_ctx, "alert tcp any any -> any any " "(msg:\"Priority test\"; sid:1;)"); - last->next = sig; - last = sig; - result &= (sig != NULL); - result &= (sig->prio == 3); + if (last != NULL) + last->next = sig; + if (sig == NULL) { + result &= 0; + } else { + result &= (sig->prio == 3); + } SigCleanSignatures(de_ctx); DetectEngineCtxFree(de_ctx); diff --git a/src/detect-threshold.c b/src/detect-threshold.c index f2e5acb693..ccbe5f72df 100644 --- a/src/detect-threshold.c +++ b/src/detect-threshold.c @@ -158,11 +158,17 @@ static DetectThresholdData *DetectThresholdParse (char *rawstr) second_pos = i+1; } - if (ByteExtractStringUint32(&de->count, 10, strlen(args[count_pos]), args[count_pos]) <= 0) { + if (args[count_pos] != NULL && + (ByteExtractStringUint32(&de->count, 10, strlen(args[count_pos]), + args[count_pos]) <= 0)) + { goto error; } - if (ByteExtractStringUint32(&de->seconds, 10, strlen(args[second_pos]), args[second_pos]) <= 0) { + if (args[second_pos] != NULL && + ByteExtractStringUint32(&de->seconds, 10, strlen(args[second_pos]), + args[second_pos]) <= 0) + { goto error; } diff --git a/src/detect-tls-version.c b/src/detect-tls-version.c index f8cae376ed..f3a120770c 100644 --- a/src/detect-tls-version.c +++ b/src/detect-tls-version.c @@ -301,7 +301,7 @@ static int DetectTlsVersionTestDetect01(void) { Packet p; Signature *s = NULL; ThreadVars th_v; - DetectEngineThreadCtx *det_ctx; + DetectEngineThreadCtx *det_ctx = NULL; memset(&th_v, 0, sizeof(th_v)); memset(&p, 0, sizeof(p)); @@ -415,7 +415,7 @@ static int DetectTlsVersionTestDetect02(void) { Packet p; Signature *s = NULL; ThreadVars th_v; - DetectEngineThreadCtx *det_ctx; + DetectEngineThreadCtx *det_ctx = NULL; memset(&th_v, 0, sizeof(th_v)); memset(&p, 0, sizeof(p)); @@ -527,7 +527,7 @@ static int DetectTlsVersionTestDetect03(void) { Packet p; Signature *s = NULL; ThreadVars th_v; - DetectEngineThreadCtx *det_ctx; + DetectEngineThreadCtx *det_ctx = NULL; memset(&th_v, 0, sizeof(th_v)); memset(&p, 0, sizeof(p)); diff --git a/src/detect-uricontent.c b/src/detect-uricontent.c index 65af8af7a2..cd925e28ca 100644 --- a/src/detect-uricontent.c +++ b/src/detect-uricontent.c @@ -696,7 +696,7 @@ int DetectUriSigTest01(void) SigMatch *sm = NULL; int result = 0; ThreadVars th_v; - DetectEngineThreadCtx *det_ctx; + DetectEngineThreadCtx *det_ctx = NULL; Signature *s = NULL; memset(&th_v, 0, sizeof(th_v)); @@ -745,7 +745,7 @@ static int DetectUriSigTest02(void) { Packet p; Signature *s = NULL; ThreadVars th_v; - DetectEngineThreadCtx *det_ctx; + DetectEngineThreadCtx *det_ctx = NULL; HtpState *http_state = NULL; memset(&th_v, 0, sizeof(th_v)); @@ -857,7 +857,7 @@ static int DetectUriSigTest03(void) { Packet p; Signature *s = NULL; ThreadVars th_v; - DetectEngineThreadCtx *det_ctx; + DetectEngineThreadCtx *det_ctx = NULL; memset(&th_v, 0, sizeof(th_v)); memset(&p, 0, sizeof(p)); @@ -1039,15 +1039,16 @@ static int DetectUriSigTest04(void) { "uricontent:\"foo\"; content:\"bar\";" " depth:10; offset: 5; content:" "\"two_contents\"; within:30; sid:1;)"); - if (s == NULL || - s->umatch == NULL || - s->pmatch == NULL || - ((DetectContentData*)s->pmatch->ctx)->depth != 8|| - ((DetectContentData*)s->pmatch->ctx)->offset != 5 || - ((DetectContentData*)s->pmatch_tail->ctx)->within != 30 || - s->match != NULL) + if (s == NULL) { + goto end; + } else if (s->umatch == NULL || + s->pmatch == NULL || + ((DetectContentData*) s->pmatch->ctx)->depth != 8 || + ((DetectContentData*) s->pmatch->ctx)->offset != 5 || + ((DetectContentData*) s->pmatch_tail->ctx)->within != 30 || + s->match != NULL) { - DetectContentPrint((DetectContentData*)s->pmatch_tail->ctx); + DetectContentPrint((DetectContentData*) s->pmatch_tail->ctx); goto end; } @@ -1056,15 +1057,16 @@ static int DetectUriSigTest04(void) { "uricontent:\"foo\"; content:\"bar\";" " depth:10; offset: 5; uricontent:" "\"two_uricontents\"; within:30; sid:1;)"); - if (s == NULL || - s->umatch == NULL || - s->pmatch == NULL || - ((DetectContentData*)s->pmatch->ctx)->depth != 8|| - ((DetectContentData*)s->pmatch->ctx)->offset != 5 || - ((DetectContentData*)s->umatch_tail->ctx)->within != 30 || - s->match != NULL) + if (s == NULL) { + goto end; + } else if (s->umatch == NULL || + s->pmatch == NULL || + ((DetectContentData*) s->pmatch->ctx)->depth != 8 || + ((DetectContentData*) s->pmatch->ctx)->offset != 5 || + ((DetectContentData*) s->umatch_tail->ctx)->within != 30 || + s->match != NULL) { - DetectUricontentPrint((DetectUricontentData*)s->umatch_tail->ctx); + DetectUricontentPrint((DetectUricontentData*) s->umatch_tail->ctx); goto end; } @@ -1073,15 +1075,17 @@ static int DetectUriSigTest04(void) { "uricontent:\"foo\"; content:\"bar\";" " depth:10; offset: 5; content:" "\"two_contents\"; distance:30; sid:1;)"); - if (s == NULL || - s->umatch == NULL || - s->pmatch == NULL || - ((DetectContentData*)s->pmatch->ctx)->depth != 8|| - ((DetectContentData*)s->pmatch->ctx)->offset != 5 || - ((DetectContentData*)s->pmatch_tail->ctx)->distance != 30 || - s->match != NULL) + if (s == NULL) { + goto end; + } else if ( + s->umatch == NULL || + s->pmatch == NULL || + ((DetectContentData*) s->pmatch->ctx)->depth != 8 || + ((DetectContentData*) s->pmatch->ctx)->offset != 5 || + ((DetectContentData*) s->pmatch_tail->ctx)->distance != 30 || + s->match != NULL) { - DetectContentPrint((DetectContentData*)s->pmatch_tail->ctx); + DetectContentPrint((DetectContentData*) s->pmatch_tail->ctx); goto end; } @@ -1090,15 +1094,17 @@ static int DetectUriSigTest04(void) { "uricontent:\"foo\"; content:\"bar\";" " depth:10; offset: 5; uricontent:" "\"two_uricontents\"; distance:30; sid:1;)"); - if (s == NULL || - s->umatch == NULL || - s->pmatch == NULL || - ((DetectContentData*)s->pmatch->ctx)->depth != 8|| - ((DetectContentData*)s->pmatch->ctx)->offset != 5 || - ((DetectContentData*)s->umatch_tail->ctx)->distance != 30 || - s->match != NULL) + if (s == NULL) { + goto end; + } else if ( + s->umatch == NULL || + s->pmatch == NULL || + ((DetectContentData*) s->pmatch->ctx)->depth != 8 || + ((DetectContentData*) s->pmatch->ctx)->offset != 5 || + ((DetectContentData*) s->umatch_tail->ctx)->distance != 30 || + s->match != NULL) { - DetectUricontentPrint((DetectUricontentData*)s->umatch_tail->ctx); + DetectUricontentPrint((DetectUricontentData*) s->umatch_tail->ctx); goto end; } @@ -1109,18 +1115,18 @@ static int DetectUriSigTest04(void) { "\"two_uricontents\"; distance:30; " "within:60; content:\"two_contents\";" " within:70; distance:45; sid:1;)"); - if (s == NULL || - s->umatch == NULL || - s->pmatch == NULL || - ((DetectContentData*)s->pmatch->ctx)->depth != 8 || - ((DetectContentData*)s->pmatch->ctx)->offset != 5 || - ((DetectContentData*)s->umatch_tail->ctx)->distance != 30 || - ((DetectContentData*)s->umatch_tail->ctx)->within != 60 || - ((DetectContentData*)s->pmatch_tail->ctx)->distance != 45 || - ((DetectContentData*)s->pmatch_tail->ctx)->within != 70 || - s->match != NULL) - { - DetectUricontentPrint((DetectUricontentData*)s->umatch_tail->ctx); + if (s == NULL) { + goto end; + } else if (s->umatch == NULL || + s->pmatch == NULL || + ((DetectContentData*) s->pmatch->ctx)->depth != 8 || + ((DetectContentData*) s->pmatch->ctx)->offset != 5 || + ((DetectContentData*) s->umatch_tail->ctx)->distance != 30 || + ((DetectContentData*) s->umatch_tail->ctx)->within != 60 || + ((DetectContentData*) s->pmatch_tail->ctx)->distance != 45 || + ((DetectContentData*) s->pmatch_tail->ctx)->within != 70 || + s->match != NULL) { + DetectUricontentPrint((DetectUricontentData*) s->umatch_tail->ctx); goto end; } @@ -1145,7 +1151,7 @@ static int DetectUriSigTest05(void) { Packet p; Signature *s = NULL; ThreadVars th_v; - DetectEngineThreadCtx *det_ctx; + DetectEngineThreadCtx *det_ctx = NULL; memset(&th_v, 0, sizeof(th_v)); memset(&p, 0, sizeof(p)); @@ -1255,7 +1261,7 @@ static int DetectUriSigTest06(void) { Packet p; Signature *s = NULL; ThreadVars th_v; - DetectEngineThreadCtx *det_ctx; + DetectEngineThreadCtx *det_ctx = NULL; memset(&th_v, 0, sizeof(th_v)); memset(&p, 0, sizeof(p)); @@ -1372,7 +1378,7 @@ static int DetectUriSigTest07(void) { Packet p; Signature *s = NULL; ThreadVars th_v; - DetectEngineThreadCtx *det_ctx; + DetectEngineThreadCtx *det_ctx = NULL; memset(&th_v, 0, sizeof(th_v)); memset(&p, 0, sizeof(p)); diff --git a/src/detect.c b/src/detect.c index 8c2a4e4067..1420a87190 100644 --- a/src/detect.c +++ b/src/detect.c @@ -2488,6 +2488,7 @@ int SigAddressCleanupStage1(DetectEngineCtx *de_ctx) { void DbgPrintSigs(DetectEngineCtx *de_ctx, SigGroupHead *sgh) { if (sgh == NULL) { printf("\n"); + return; } uint32_t sig; @@ -3430,7 +3431,7 @@ static int SigTest07Real (int mpm_type) { uint16_t buflen = strlen((char *)buf); Packet p; ThreadVars th_v; - DetectEngineThreadCtx *det_ctx; + DetectEngineThreadCtx *det_ctx = NULL; Flow f; TcpSession ssn; int result = 0; @@ -3912,13 +3913,12 @@ static int SigTest12Real (int mpm_type) { else result = 0; + if (det_ctx != NULL) + DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx); end: if (de_ctx != NULL) { SigGroupCleanup(de_ctx); SigCleanSignatures(de_ctx); - if (det_ctx != NULL) - DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx); - //PatternMatchDestroy(mpm_ctx); DetectEngineCtxFree(de_ctx); } return result; @@ -4198,7 +4198,7 @@ static int SigTest17Real (int mpm_type) { uint16_t buflen = strlen((char *)buf); Packet p; ThreadVars th_v; - DetectEngineThreadCtx *det_ctx; + DetectEngineThreadCtx *det_ctx = NULL; int result = 0; memset(&th_v, 0, sizeof(th_v)); @@ -5868,6 +5868,7 @@ int SigTest34ICMPV4Keyword(void) p1.icmpv4c.comp_csum = -1; p1.ip4h = (IPV4Hdr *)(valid_raw_ipv4); + p1.ip4h->ip_verhl = 69; p1.icmpv4h = (ICMPV4Hdr *) (valid_raw_ipv4 + IPV4_GET_RAW_HLEN(p1.ip4h) * 4); p1.src.family = AF_INET; p1.dst.family = AF_INET; @@ -5877,6 +5878,7 @@ int SigTest34ICMPV4Keyword(void) p2.icmpv4c.comp_csum = -1; p2.ip4h = (IPV4Hdr *)(invalid_raw_ipv4); + p2.ip4h->ip_verhl = 69; p2.icmpv4h = (ICMPV4Hdr *) (invalid_raw_ipv4 + IPV4_GET_RAW_HLEN(p2.ip4h) * 4); p2.src.family = AF_INET; p2.dst.family = AF_INET; @@ -5976,6 +5978,7 @@ int SigTest35NegativeICMPV4Keyword(void) p1.icmpv4c.comp_csum = -1; p1.ip4h = (IPV4Hdr *)(valid_raw_ipv4); + p1.ip4h->ip_verhl = 69; p1.icmpv4h = (ICMPV4Hdr *) (valid_raw_ipv4 + IPV4_GET_RAW_HLEN(p1.ip4h) * 4); p1.src.family = AF_INET; p1.dst.family = AF_INET; @@ -5985,6 +5988,7 @@ int SigTest35NegativeICMPV4Keyword(void) p2.icmpv4c.comp_csum = -1; p2.ip4h = (IPV4Hdr *)(invalid_raw_ipv4); + p2.ip4h->ip_verhl = 69; p2.icmpv4h = (ICMPV4Hdr *) (invalid_raw_ipv4 + IPV4_GET_RAW_HLEN(p2.ip4h) * 4); p2.src.family = AF_INET; p2.dst.family = AF_INET; diff --git a/src/tmqh-packetpool.c b/src/tmqh-packetpool.c index 603c95ab0e..0757096c85 100644 --- a/src/tmqh-packetpool.c +++ b/src/tmqh-packetpool.c @@ -87,7 +87,9 @@ void TmqhOutputPacketpool(ThreadVars *t, Packet *p) } } else { //printf("TmqhOutputPacketpool: NOT IS_TUNNEL_ROOT_PKT\n"); - if (p->root->tunnel_verdicted == 1 && TUNNEL_PKT_TPR(p) == 1) { + if (p->root != NULL && p->root->tunnel_verdicted == 1 && + TUNNEL_PKT_TPR(p) == 1) + { //printf("TmqhOutputPacketpool: p->root->tunnel_verdicted == 1 && TUNNEL_PKT_TPR(p) == 1\n"); /* the root is ready and we are the last tunnel packet, * lets enqueue them both. */ diff --git a/src/util-debug-filters.c b/src/util-debug-filters.c index 552259c0a9..9c05cb4b2d 100644 --- a/src/util-debug-filters.c +++ b/src/util-debug-filters.c @@ -807,7 +807,8 @@ void SCLogCheckFDFilterExit(const char *function) SCMutexUnlock(&sc_log_fd_filters_tl_m); - thread_list->entered--; + if (thread_list != NULL) + thread_list->entered--; return; } diff --git a/src/util-radix-tree.c b/src/util-radix-tree.c index 1a40783ada..fc01e82d6b 100644 --- a/src/util-radix-tree.c +++ b/src/util-radix-tree.c @@ -514,9 +514,10 @@ static void SCRadixReleaseRadixSubtree(SCRadixNode *node, SCRadixTree *tree) */ void SCRadixReleaseRadixTree(SCRadixTree *tree) { - if (tree != NULL) - SCRadixReleaseRadixSubtree(tree->head, tree); + if (tree == NULL) + return; + SCRadixReleaseRadixSubtree(tree->head, tree); tree->head = NULL; return; @@ -1601,11 +1602,12 @@ void SCRadixPrintNodeInfo(SCRadixNode *node, int level, void (*PrintData)(void* printf("%d [", node->bit); - if (node->netmasks == NULL) + if (node->netmasks == NULL) { printf("%d, ", -1); - - for (i = 0; i < node->netmask_cnt; i++) - printf("%s%d", (0 == i ? "" : ", "), node->netmasks[i]); + } else { + for (i = 0; i < node->netmask_cnt; i++) + printf("%s%d", (0 == i ? "" : ", "), node->netmasks[i]); + } printf("] ("); if (node->prefix != NULL) { diff --git a/src/util-unittest-helper.c b/src/util-unittest-helper.c index e233c61704..52d51e9517 100644 --- a/src/util-unittest-helper.c +++ b/src/util-unittest-helper.c @@ -552,11 +552,11 @@ int UTHMatchPackets(DetectEngineCtx *de_ctx, Packet **p, int num_packets) { * the de_ctx can have multiple signatures, and some of them may match * and others may not. That check will be outside */ -end: - SigGroupCleanup(de_ctx); if (det_ctx != NULL) { DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx); } +end: + if (de_ctx != NULL) SigGroupCleanup(de_ctx); return result; }