diff --git a/src/detect-csum.c b/src/detect-csum.c index 8ad4bb60b8..9ef4b230e3 100644 --- a/src/detect-csum.c +++ b/src/detect-csum.c @@ -177,7 +177,8 @@ void DetectCsumRegister (void) * \param cd Pointer to the DetectCsumData structure that holds the keyword * value sent as argument * - * \retval 1 if the keyvalue has been parsed successfully, and 0 otherwise + * \retval 1 the keyvalue has been parsed successfully + * \retval 0 error */ static int DetectCsumParseArg(const char *key, DetectCsumData *cd) { @@ -186,8 +187,12 @@ static int DetectCsumParseArg(const char *key, DetectCsumData *cd) if (key[0] == '\"' && key[strlen(key) - 1] == '\"') { str = SCStrdup(key + 1); str[strlen(key) - 2] = '\0'; - } else + } else { str = SCStrdup(key); + } + if (str == NULL) { + goto error; + } if (strcasecmp(str, DETECT_CSUM_VALID) == 0 || strcasecmp(str, DETECT_CSUM_INVALID) == 0) { @@ -196,7 +201,9 @@ static int DetectCsumParseArg(const char *key, DetectCsumData *cd) return 1; } - SCFree(str); +error: + if (str != NULL) + SCFree(str); return 0; } diff --git a/src/detect-rev.c b/src/detect-rev.c index 1e0df2ab89..1e16857dd5 100644 --- a/src/detect-rev.c +++ b/src/detect-rev.c @@ -46,13 +46,17 @@ static int DetectRevSetup (DetectEngineCtx *de_ctx, Signature *s, char *rawstr) /* strip "'s */ if (rawstr[0] == '\"' && rawstr[strlen(rawstr)-1] == '\"') { str = SCStrdup(rawstr+1); + if (str == NULL) + return -1; + str[strlen(rawstr)-2] = '\0'; dubbed = 1; } s->rev = (uint8_t)atoi(str); - if (dubbed) SCFree(str); + if (dubbed) + SCFree(str); return 0; } diff --git a/src/detect-sid.c b/src/detect-sid.c index 9cf62b39f2..ed25869502 100644 --- a/src/detect-sid.c +++ b/src/detect-sid.c @@ -46,13 +46,17 @@ static int DetectSidSetup (DetectEngineCtx *de_ctx, Signature *s, char *sidstr) /* strip "'s */ if (sidstr[0] == '\"' && sidstr[strlen(sidstr)-1] == '\"') { str = SCStrdup(sidstr+1); + if (str == NULL) + return -1; + str[strlen(sidstr)-2] = '\0'; dubbed = 1; } s->id = (uint32_t)atoi(str); - if (dubbed) SCFree(str); + if (dubbed) + SCFree(str); return 0; }