detect-id: clean up to suppress minor coverity warning

pull/2952/head
Victor Julien 8 years ago
parent 97cb5d3973
commit 319a6f48ff

@ -129,23 +129,20 @@ static DetectIdData *DetectIdParse (const char *idstr)
ov, MAX_SUBSTRINGS); ov, MAX_SUBSTRINGS);
if (ret < 1 || ret > 3) { if (ret < 1 || ret > 3) {
SCLogError(SC_ERR_PCRE_MATCH, "invalid id option. The id option value must be" SCLogError(SC_ERR_INVALID_VALUE, "invalid id option '%s'. The id option "
" in the range %u - %u", "value must be in the range %u - %u",
DETECT_IPID_MIN, DETECT_IPID_MAX); idstr, DETECT_IPID_MIN, DETECT_IPID_MAX);
goto error; return NULL;
} }
if (ret > 1) {
char copy_str[128] = ""; char copy_str[128] = "";
char *tmp_str; char *tmp_str;
res = pcre_copy_substring((char *)idstr, ov, MAX_SUBSTRINGS, 1, res = pcre_copy_substring((char *)idstr, ov, MAX_SUBSTRINGS, 1,
copy_str, sizeof(copy_str)); copy_str, sizeof(copy_str));
if (res < 0) { if (res < 0) {
SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre_copy_substring failed"); SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre_copy_substring failed");
goto error; return NULL;
} }
tmp_str = copy_str; tmp_str = copy_str;
/* Let's see if we need to scape "'s */ /* Let's see if we need to scape "'s */
@ -159,29 +156,21 @@ static DetectIdData *DetectIdParse (const char *idstr)
temp = atoi((char *)tmp_str); temp = atoi((char *)tmp_str);
if (temp > DETECT_IPID_MAX) { if (temp > DETECT_IPID_MAX) {
SCLogError(SC_ERR_INVALID_VALUE, "\"id\" option must be in " SCLogError(SC_ERR_INVALID_VALUE, "invalid id option '%s'. The id option "
"the range %u - %u", "value must be in the range %u - %u",
DETECT_IPID_MIN, DETECT_IPID_MAX); idstr, DETECT_IPID_MIN, DETECT_IPID_MAX);
goto error; return NULL;
} }
/* We have a correct id option */ /* We have a correct id option */
id_d = SCMalloc(sizeof(DetectIdData)); id_d = SCMalloc(sizeof(DetectIdData));
if (unlikely(id_d == NULL)) if (unlikely(id_d == NULL))
goto error; return NULL;
id_d->id = temp; id_d->id = temp;
SCLogDebug("detect-id: will look for ip_id: %u\n", id_d->id); SCLogDebug("detect-id: will look for ip_id: %u\n", id_d->id);
}
return id_d; return id_d;
error:
if (id_d != NULL)
DetectIdFree(id_d);
return NULL;
} }
/** /**
@ -202,27 +191,22 @@ int DetectIdSetup (DetectEngineCtx *de_ctx, Signature *s, const char *idstr)
id_d = DetectIdParse(idstr); id_d = DetectIdParse(idstr);
if (id_d == NULL) if (id_d == NULL)
goto error; return -1;
/* Okay so far so good, lets get this into a SigMatch /* Okay so far so good, lets get this into a SigMatch
* and put it in the Signature. */ * and put it in the Signature. */
sm = SigMatchAlloc(); sm = SigMatchAlloc();
if (sm == NULL) if (sm == NULL) {
goto error; DetectIdFree(id_d);
return -1;
}
sm->type = DETECT_ID; sm->type = DETECT_ID;
sm->ctx = (SigMatchCtx *)id_d; sm->ctx = (SigMatchCtx *)id_d;
SigMatchAppendSMToList(s, sm, DETECT_SM_LIST_MATCH); SigMatchAppendSMToList(s, sm, DETECT_SM_LIST_MATCH);
s->flags |= SIG_FLAG_REQUIRE_PACKET; s->flags |= SIG_FLAG_REQUIRE_PACKET;
return 0; return 0;
error:
if (id_d != NULL) DetectIdFree(id_d);
if (sm != NULL) SCFree(sm);
return -1;
} }
/** /**

Loading…
Cancel
Save