From: Victor Julien Date: Mon, 9 Dec 2013 20:03:44 +0000 (+0100) Subject: Fix realloc error handling in threshold.config file parsing. Bug #1062. X-Git-Tag: suricata-2.0beta2~47 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b4631794a85ca478ede81281107a4fea70bed59a;p=thirdparty%2Fsuricata.git Fix realloc error handling in threshold.config file parsing. Bug #1062. --- diff --git a/src/util-threshold-config.c b/src/util-threshold-config.c index 7a0ea7df3a..b35208d7b7 100644 --- a/src/util-threshold-config.c +++ b/src/util-threshold-config.c @@ -1149,14 +1149,20 @@ void SCThresholdConfParseFile(DetectEngineCtx *de_ctx, FILE *fd) len = SCThresholdConfLineLength(fd); if (len > 0) { - if (line == NULL) - line = SCRealloc(line, len + 1); - else - line = SCRealloc(line, strlen(line) + len + 1); - - if (unlikely(line == NULL)) { - SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); - break; + if (line == NULL) { + line = SCMalloc(len + 1); + if (unlikely(line == NULL)) { + SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); + return; + } + } else { + char *newline = SCRealloc(line, strlen(line) + len + 1); + if (unlikely(newline == NULL)) { + SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); + SCFree(line); + return; + } + line = newline; } if (fgets(line + esc_pos, len + 1, fd) == NULL)