DNP3: don't leak memory on dnp3_obj parsing

pull/2391/head
Victor Julien 8 years ago
parent f0de1d04a9
commit 7cf231c7ec

@ -339,35 +339,26 @@ error:
*/ */
static int DetectDNP3ObjParse(const char *str, uint8_t *group, uint8_t *var) static int DetectDNP3ObjParse(const char *str, uint8_t *group, uint8_t *var)
{ {
char *groupstr = NULL, *varstr, *sep; size_t size = strlen(str) + 1;
int result = 0; char groupstr[size], *varstr, *sep;
strlcpy(groupstr, str, size);
groupstr = SCStrdup(str);
if (unlikely(groupstr == NULL)) {
return 0;
}
sep = strchr(groupstr, ','); sep = strchr(groupstr, ',');
if (sep == NULL) { if (sep == NULL) {
goto fail; return 0;
} }
*sep = '\0'; *sep = '\0';
varstr = sep + 1; varstr = sep + 1;
if (ByteExtractStringUint8(group, 0, strlen(groupstr), groupstr) < 0) { if (ByteExtractStringUint8(group, 0, strlen(groupstr), groupstr) < 0) {
goto fail; return 0;
} }
if (ByteExtractStringUint8(var, 0, strlen(varstr), varstr) < 0) { if (ByteExtractStringUint8(var, 0, strlen(varstr), varstr) < 0) {
goto fail; return 0;
} }
result = 1; return 1;
fail:
if (groupstr == NULL) {
SCFree(groupstr);
}
return result;
} }
static int DetectDNP3ObjSetup(DetectEngineCtx *de_ctx, Signature *s, char *str) static int DetectDNP3ObjSetup(DetectEngineCtx *de_ctx, Signature *s, char *str)

Loading…
Cancel
Save