fixed the memory leaks and buffer overflows reported by parfait

remotes/origin/master-1.0.x
Gurvinder Singh 16 years ago committed by Victor Julien
parent 27d1dbc342
commit cf2d254cc6

@ -429,12 +429,11 @@ static int AlertUnifiedAlertTestRotate01(void)
memset(&tv, 0, sizeof(ThreadVars)); memset(&tv, 0, sizeof(ThreadVars));
if (lf == NULL)
return 0;
ret = AlertUnifiedAlertThreadInit(&tv, oc, &data); ret = AlertUnifiedAlertThreadInit(&tv, oc, &data);
if (ret == TM_ECODE_FAILED) { if (ret == TM_ECODE_FAILED) {
LogFileFreeCtx(lf); LogFileFreeCtx(lf);
if (filename != NULL)
free(filename);
return 0; return 0;
} }
@ -452,6 +451,7 @@ static int AlertUnifiedAlertTestRotate01(void)
error: error:
AlertUnifiedAlertThreadDeinit(&tv, data); AlertUnifiedAlertThreadDeinit(&tv, data);
if (oc != NULL) AlertUnifiedAlertDeInitCtx(oc); if (oc != NULL) AlertUnifiedAlertDeInitCtx(oc);
if (filename != NULL) free(filename);
return r; return r;
} }
#endif /* UNITTESTS */ #endif /* UNITTESTS */

@ -449,12 +449,11 @@ static int AlertUnifiedLogTestRotate01(void)
memset(&tv, 0, sizeof(ThreadVars)); memset(&tv, 0, sizeof(ThreadVars));
if (lf == NULL)
return 0;
ret = AlertUnifiedLogThreadInit(&tv, oc, &data); ret = AlertUnifiedLogThreadInit(&tv, oc, &data);
if (ret == TM_ECODE_FAILED) { if (ret == TM_ECODE_FAILED) {
LogFileFreeCtx(lf); LogFileFreeCtx(lf);
if (filename != NULL)
free(filename);
return 0; return 0;
} }
@ -472,6 +471,7 @@ static int AlertUnifiedLogTestRotate01(void)
error: error:
AlertUnifiedLogThreadDeinit(&tv, data); AlertUnifiedLogThreadDeinit(&tv, data);
if (oc != NULL) AlertUnifiedLogDeInitCtx(oc); if (oc != NULL) AlertUnifiedLogDeInitCtx(oc);
if (filename != NULL) free(filename);
return r; return r;
} }
#endif /* UNITTESTS */ #endif /* UNITTESTS */

@ -1059,12 +1059,11 @@ static int Unified2TestRotate01(void)
memset(&tv, 0, sizeof(ThreadVars)); memset(&tv, 0, sizeof(ThreadVars));
if (lf == NULL)
return 0;
ret = Unified2AlertThreadInit(&tv, oc, &data); ret = Unified2AlertThreadInit(&tv, oc, &data);
if (ret == TM_ECODE_FAILED) { if (ret == TM_ECODE_FAILED) {
LogFileFreeCtx(lf); LogFileFreeCtx(lf);
if (filename != NULL)
free(filename);
return 0; return 0;
} }

@ -993,7 +993,11 @@ int DetectAddressParse2(DetectAddressHead *gh, DetectAddressHead *ghn, char *s,
} else if (depth == 0 && s[u] == '$') { } else if (depth == 0 && s[u] == '$') {
d_set = 1; d_set = 1;
} else if (depth == 0 && u == size - 1) { } else if (depth == 0 && u == size - 1) {
if (x == 1024) {
address[x - 1] = '\0';
} else {
address[x] = '\0'; address[x] = '\0';
}
x = 0; x = 0;
if (d_set == 1) { if (d_set == 1) {

@ -402,7 +402,11 @@ IPOnlyCIDRItem *IPOnlyCIDRListParse2(char *s, int negate)
} else if (depth == 0 && s[u] == '$') { } else if (depth == 0 && s[u] == '$') {
d_set = 1; d_set = 1;
} else if (depth == 0 && u == size - 1) { } else if (depth == 0 && u == size - 1) {
if (x == 1024) {
address[x - 1] = '\0';
} else {
address[x] = '\0'; address[x] = '\0';
}
x = 0; x = 0;
if (d_set == 1) { if (d_set == 1) {

@ -1079,7 +1079,11 @@ static int DetectPortParseDo(DetectPort **head, DetectPort **nhead, char *s,
d_set = 1; d_set = 1;
} else if (depth == 0 && u == size-1) { } else if (depth == 0 && u == size-1) {
range = 0; range = 0;
if (x == 1024) {
address[x - 1] = '\0';
} else {
address[x] = '\0'; address[x] = '\0';
}
SCLogDebug("%s", address); SCLogDebug("%s", address);
x = 0; x = 0;
if (d_set == 1) { if (d_set == 1) {

@ -113,7 +113,7 @@ int DetectFragOffsetMatch (ThreadVars *t, DetectEngineThreadCtx *det_ctx, Packet
*/ */
DetectFragOffsetData *DetectFragOffsetParse (char *fragoffsetstr) { DetectFragOffsetData *DetectFragOffsetParse (char *fragoffsetstr) {
DetectFragOffsetData *fragoff = NULL; DetectFragOffsetData *fragoff = NULL;
char *substr[2] = {NULL, NULL}; char *substr[3] = {NULL, NULL, NULL};
#define MAX_SUBSTRINGS 30 #define MAX_SUBSTRINGS 30
int ret = 0, res = 0; int ret = 0, res = 0;
int ov[MAX_SUBSTRINGS]; int ov[MAX_SUBSTRINGS];
@ -164,14 +164,14 @@ DetectFragOffsetData *DetectFragOffsetParse (char *fragoffsetstr) {
ByteExtractStringUint16(&fragoff->frag_off, 10, 0, substr[1]); ByteExtractStringUint16(&fragoff->frag_off, 10, 0, substr[1]);
for (i = 0; i < 2; i++) { for (i = 0; i < 3; i++) {
if (substr[i] != NULL) SCFree(substr[i]); if (substr[i] != NULL) SCFree(substr[i]);
} }
return fragoff; return fragoff;
error: error:
for (i = 0; i < 2; i++) { for (i = 0; i < 3; i++) {
if (substr[i] != NULL) SCFree(substr[i]); if (substr[i] != NULL) SCFree(substr[i]);
} }
if (fragoff != NULL) DetectFragOffsetFree(fragoff); if (fragoff != NULL) DetectFragOffsetFree(fragoff);

@ -269,25 +269,38 @@ SCError SCLogMessage(SCLogLevel log_level, char **msg, const char *file,
printf("Logging module not initialized. Call SCLogInitLogModule(), " printf("Logging module not initialized. Call SCLogInitLogModule(), "
"before using the logging API\n"); "before using the logging API\n");
#endif #endif
if (temp_fmt != NULL)
free(temp_fmt);
return SC_ERR_LOG_MODULE_NOT_INIT; return SC_ERR_LOG_MODULE_NOT_INIT;
} }
if (sc_log_fg_filters_present == 1) { if (sc_log_fg_filters_present == 1) {
if (SCLogMatchFGFilterWL(file, function, line) != 1) if (SCLogMatchFGFilterWL(file, function, line) != 1) {
if (temp_fmt != NULL)
free(temp_fmt);
return SC_ERR_LOG_FG_FILTER_MATCH; return SC_ERR_LOG_FG_FILTER_MATCH;
}
if (SCLogMatchFGFilterBL(file, function, line) != 1) if (SCLogMatchFGFilterBL(file, function, line) != 1) {
if (temp_fmt != NULL)
free(temp_fmt);
return SC_ERR_LOG_FG_FILTER_MATCH; return SC_ERR_LOG_FG_FILTER_MATCH;
} }
}
if (sc_log_fd_filters_present == 1 && SCLogMatchFDFilter(function) != 1) if (sc_log_fd_filters_present == 1 && SCLogMatchFDFilter(function) != 1) {
if (temp_fmt != NULL)
free(temp_fmt);
return SC_ERR_LOG_FG_FILTER_MATCH; return SC_ERR_LOG_FG_FILTER_MATCH;
}
while ( (temp_fmt = index(temp_fmt, SC_LOG_FMT_PREFIX)) ) { while ( (temp_fmt = index(temp_fmt, SC_LOG_FMT_PREFIX)) ) {
if ((temp - *msg) > SC_LOG_MAX_LOG_MSG_LEN) { if ((temp - *msg) > SC_LOG_MAX_LOG_MSG_LEN) {
printf("Warning: Log message exceeded message length limit of %d\n", printf("Warning: Log message exceeded message length limit of %d\n",
SC_LOG_MAX_LOG_MSG_LEN); SC_LOG_MAX_LOG_MSG_LEN);
*msg = *msg + SC_LOG_MAX_LOG_MSG_LEN; *msg = *msg + SC_LOG_MAX_LOG_MSG_LEN;
if (temp_fmt_h != NULL)
free(temp_fmt_h);
return SC_OK; return SC_OK;
} }
switch(temp_fmt[1]) { switch(temp_fmt[1]) {
@ -414,6 +427,8 @@ SCError SCLogMessage(SCLogLevel log_level, char **msg, const char *file,
return SC_OK; return SC_OK;
error: error:
if (temp_fmt != NULL)
free(temp_fmt_h);
return SC_ERR_SPRINTF; return SC_ERR_SPRINTF;
} }

@ -974,8 +974,8 @@ SCRadixNode *SCRadixAddKeyIPV4String(const char *str, SCRadixTree *tree, void *u
struct in_addr addr; struct in_addr addr;
/* Make a copy of the string so it can be modified */ /* Make a copy of the string so it can be modified */
strncpy(ip_str, str, sizeof(ip_str) - 1); strncpy(ip_str, str, sizeof(ip_str) - 2);
*(ip_str + sizeof(ip_str)) = '\0'; *(ip_str + (sizeof(ip_str) - 1)) = '\0';
/* Does it have a mask? */ /* Does it have a mask? */
if (NULL != (mask_str = strchr(ip_str, '/'))) { if (NULL != (mask_str = strchr(ip_str, '/'))) {
@ -1022,8 +1022,8 @@ SCRadixNode *SCRadixAddKeyIPV6String(const char *str, SCRadixTree *tree, void *u
struct in6_addr addr; struct in6_addr addr;
/* Make a copy of the string so it can be modified */ /* Make a copy of the string so it can be modified */
strncpy(ip_str, str, sizeof(ip_str) - 1); strncpy(ip_str, str, sizeof(ip_str) - 2);
*(ip_str + sizeof(ip_str)) = '\0'; *(ip_str + sizeof(ip_str) - 1) = '\0';
/* Does it have a mask? */ /* Does it have a mask? */
if (NULL != (mask_str = strchr(ip_str, '/'))) { if (NULL != (mask_str = strchr(ip_str, '/'))) {

@ -968,7 +968,7 @@ int UtilSpmSearchOffsetsTest01() {
int i, j; int i, j;
uint8_t *found = NULL; uint8_t *found = NULL;
for (i = 0; i < 26; i++) { for (i = 0; i < 26; i++) {
for (j = 0; j <= 26 - i; j++) { for (j = 0; j <= (26 - i); j++) {
found = BasicSearchWrapper((uint8_t *)text[i][j], (uint8_t *)needle[i], 1); found = BasicSearchWrapper((uint8_t *)text[i][j], (uint8_t *)needle[i], 1);
if (found == 0) { if (found == 0) {
printf("Error1 searching for %s in text %s\n", needle[i], text[i][j]); printf("Error1 searching for %s in text %s\n", needle[i], text[i][j]);
@ -1403,7 +1403,7 @@ int UtilSpmSearchOffsetsNocaseTest01() {
int i, j; int i, j;
uint8_t *found = NULL; uint8_t *found = NULL;
for (i = 0; i < 26; i++) { for (i = 0; i < 26; i++) {
for (j = 0; j <= 26-i; j++) { for (j = 0; j <= (26-i); j++) {
found = BasicSearchNocaseWrapper((uint8_t *)text[i][j], (uint8_t *)needle[i], 1); found = BasicSearchNocaseWrapper((uint8_t *)text[i][j], (uint8_t *)needle[i], 1);
if (found == 0) { if (found == 0) {
printf("Error1 searching for %s in text %s\n", needle[i], text[i][j]); printf("Error1 searching for %s in text %s\n", needle[i], text[i][j]);

Loading…
Cancel
Save