detect/xbits: fix coverity warning

CID 1554237 and CID 1554233

Basically make the code easier to reason with for coverity
without changing the behavior which was fine.
pull/9882/head
Philippe Antoine 2 years ago committed by Victor Julien
parent 41c0526fdc
commit 3a79984e5e

@ -340,44 +340,39 @@ int DetectXbitSetup (DetectEngineCtx *de_ctx, Signature *s, const char *rawstr)
int result = DetectXbitParse(de_ctx, rawstr, &cd); int result = DetectXbitParse(de_ctx, rawstr, &cd);
if (result < 0) { if (result < 0) {
return -1; return -1;
} else if (cd == NULL) {
/* noalert doesn't use a cd/sm struct. It flags the sig. We're done. */ /* noalert doesn't use a cd/sm struct. It flags the sig. We're done. */
} else if (result == 0 && cd == NULL) {
s->flags |= SIG_FLAG_NOALERT; s->flags |= SIG_FLAG_NOALERT;
return 0; return 0;
} }
/* 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. */
switch (cd->cmd) { switch (cd->cmd) {
/* case DETECT_XBITS_CMD_NOALERT can't happen here */ /* case DETECT_XBITS_CMD_NOALERT can't happen here */
case DETECT_XBITS_CMD_ISNOTSET: case DETECT_XBITS_CMD_ISNOTSET:
case DETECT_XBITS_CMD_ISSET: case DETECT_XBITS_CMD_ISSET:
/* checks, so packet list */ /* checks, so packet list */
if (SigMatchAppendSMToList( if (SigMatchAppendSMToList(
de_ctx, s, DETECT_XBITS, (SigMatchCtx *)cd, DETECT_SM_LIST_MATCH) == NULL) { de_ctx, s, DETECT_XBITS, (SigMatchCtx *)cd, DETECT_SM_LIST_MATCH) == NULL) {
goto error; SCFree(cd);
return -1;
} }
break; break;
case DETECT_XBITS_CMD_SET: // all other cases
case DETECT_XBITS_CMD_UNSET: // DETECT_XBITS_CMD_SET, DETECT_XBITS_CMD_UNSET, DETECT_XBITS_CMD_TOGGLE:
case DETECT_XBITS_CMD_TOGGLE: default:
/* modifiers, only run when entire sig has matched */ /* modifiers, only run when entire sig has matched */
if (SigMatchAppendSMToList(de_ctx, s, DETECT_XBITS, (SigMatchCtx *)cd, if (SigMatchAppendSMToList(de_ctx, s, DETECT_XBITS, (SigMatchCtx *)cd,
DETECT_SM_LIST_POSTMATCH) == NULL) { DETECT_SM_LIST_POSTMATCH) == NULL) {
goto error; SCFree(cd);
return -1;
} }
break; break;
} }
return 0; return 0;
error:
if (cd != NULL)
SCFree(cd);
return -1;
} }
static void DetectXbitFree (DetectEngineCtx *de_ctx, void *ptr) static void DetectXbitFree (DetectEngineCtx *de_ctx, void *ptr)

Loading…
Cancel
Save