Better handle low memory conditions.

remotes/origin/master-1.0.x
Victor Julien 15 years ago
parent f07997fd4a
commit 718fecb6fc

@ -79,7 +79,7 @@ static uint32_t FragmentDataParser(Flow *f, void *dcerpcudp_state,
*stub_data_buffer = realloc(*stub_data_buffer, *stub_data_buffer_len + stub_len);
if (*stub_data_buffer == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
exit(EXIT_FAILURE);
goto end;
}
memcpy(*stub_data_buffer + *stub_data_buffer_len, input, stub_len);
@ -99,6 +99,7 @@ static uint32_t FragmentDataParser(Flow *f, void *dcerpcudp_state,
}
#endif
end:
SCReturnUInt((uint32_t)stub_len);
}

@ -927,7 +927,7 @@ static uint32_t StubDataParser(DCERPC *dcerpc, uint8_t *input, uint32_t input_le
*stub_data_buffer = realloc(*stub_data_buffer, *stub_data_buffer_len + stub_len);
if (*stub_data_buffer == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
exit(EXIT_FAILURE);
goto end;
}
memcpy(*stub_data_buffer + *stub_data_buffer_len, input, stub_len);
@ -947,6 +947,7 @@ static uint32_t StubDataParser(DCERPC *dcerpc, uint8_t *input, uint32_t input_le
}
#endif
end:
SCReturnUInt((uint32_t)stub_len);
}

@ -195,9 +195,11 @@ void DecodeGRE(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt, u
if (pq != NULL) {
Packet *tp = PacketPseudoPktSetup(p, pkt + header_len,
len - header_len, IPPROTO_IP);
if (tp != NULL) {
DecodeTunnel(tv, dtv, tp, tp->pkt, tp->pktlen, pq);
PacketEnqueue(pq,tp);
}
}
break;
}
@ -206,9 +208,11 @@ void DecodeGRE(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt, u
if (pq != NULL) {
Packet *tp = PacketPseudoPktSetup(p, pkt + header_len,
len - header_len, PPP_OVER_GRE);
if (tp != NULL) {
DecodeTunnel(tv, dtv, tp, tp->pkt, tp->pktlen, pq);
PacketEnqueue(pq,tp);
}
}
break;
}
@ -217,9 +221,11 @@ void DecodeGRE(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt, u
if (pq != NULL) {
Packet *tp = PacketPseudoPktSetup(p, pkt + header_len,
len - header_len, IPPROTO_IPV6);
if (tp != NULL) {
DecodeTunnel(tv, dtv, tp, tp->pkt, tp->pktlen, pq);
PacketEnqueue(pq,tp);
}
}
break;
}
@ -228,9 +234,11 @@ void DecodeGRE(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt, u
if (pq != NULL) {
Packet *tp = PacketPseudoPktSetup(p, pkt + header_len,
len - header_len, VLAN_OVER_GRE);
if (tp != NULL) {
DecodeTunnel(tv, dtv, tp, tp->pkt, tp->pktlen, pq);
PacketEnqueue(pq,tp);
}
}
break;
}

@ -563,13 +563,14 @@ void DecodeIPV4(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt,
Packet *tp = PacketPseudoPktSetup(p, pkt + IPV4_GET_HLEN(p),
IPV4_GET_IPLEN(p) - IPV4_GET_HLEN(p),
IPV4_GET_IPPROTO(p));
if (tp != NULL) {
/* send that to the Tunnel decoder */
DecodeTunnel(tv, dtv, tp, tp->pkt, tp->pktlen, pq);
/* add the tp to the packet queue. */
PacketEnqueue(pq,tp);
}
}
break;
}
case IPPROTO_GRE:

@ -284,9 +284,6 @@ void SCLogOutputBuffer(SCLogLevel log_level, char *msg)
SCError SCLogMessage(SCLogLevel log_level, char **msg, const char *file,
unsigned line, const char *function)
{
char *temp_fmt = strdup(sc_log_config->log_format);
char *temp_fmt_h = temp_fmt;
char *substr = temp_fmt;
char *temp = *msg;
const char *s = NULL;
@ -296,9 +293,12 @@ SCError SCLogMessage(SCLogLevel log_level, char **msg, const char *file,
/* no of characters_written(cw) by snprintf */
int cw = 0;
char *temp_fmt = strdup(sc_log_config->log_format);
char *temp_fmt_h = temp_fmt;
char *substr = temp_fmt;
if (temp_fmt == NULL) {
printf("Error allocating memory\n");
exit(EXIT_FAILURE);
goto error;
}
if (sc_log_module_initialized != 1) {
@ -501,7 +501,7 @@ SCLogOPBuffer *SCLogAllocLogOPBuffer(void)
SCLogOPIfaceCtx *op_iface_ctx = NULL;
int i = 0;
if ( (buffer = SCMalloc(sc_log_config->op_ifaces_cnt *
if ( (buffer = malloc(sc_log_config->op_ifaces_cnt *
sizeof(SCLogOPBuffer))) == NULL) {
SCLogError(SC_ERR_FATAL, "Fatal error encountered in SCLogAllocLogOPBuffer. Exiting...");
exit(EXIT_FAILURE);
@ -529,7 +529,7 @@ static inline SCLogOPIfaceCtx *SCLogAllocLogOPIfaceCtx()
{
SCLogOPIfaceCtx *iface_ctx = NULL;
if ( (iface_ctx = SCMalloc(sizeof(SCLogOPIfaceCtx))) == NULL) {
if ( (iface_ctx = malloc(sizeof(SCLogOPIfaceCtx))) == NULL) {
SCLogError(SC_ERR_FATAL, "Fatal error encountered in SCLogallocLogOPIfaceCtx. Exiting...");
exit(EXIT_FAILURE);
}
@ -559,28 +559,43 @@ static inline SCLogOPIfaceCtx *SCLogInitFileOPIface(const char *file,
exit(EXIT_FAILURE);
}
iface_ctx->iface = SC_LOG_OP_IFACE_FILE;
if (file != NULL &&
(iface_ctx->file = strdup(file)) == NULL) {
printf("Error allocating memory\n");
exit(EXIT_FAILURE);
if (file == NULL || log_format == NULL) {
goto error;
}
iface_ctx->iface = SC_LOG_OP_IFACE_FILE;
if ( (iface_ctx->file_d = fopen(file, "w+")) == NULL) {
printf("Error opening file %s\n", file);
return NULL;
goto error;
}
if (log_format != NULL &&
(iface_ctx->log_format = strdup(log_format)) == NULL) {
printf("Error allocating memory\n");
exit(EXIT_FAILURE);
if ((iface_ctx->file = strdup(file)) == NULL) {
goto error;
}
if ((iface_ctx->log_format = strdup(log_format)) == NULL) {
goto error;
}
iface_ctx->log_level = log_level;
return iface_ctx;
error:
if (iface_ctx->file != NULL) {
free((char *)iface_ctx->file);
iface_ctx->file = NULL;
}
if (iface_ctx->log_format != NULL) {
free((char *)iface_ctx->log_format);
iface_ctx->log_format = NULL;
}
if (iface_ctx->file_d != NULL) {
fclose(iface_ctx->file_d);
iface_ctx->file_d = NULL;
}
return NULL;
}
/**
@ -924,7 +939,7 @@ SCLogInitData *SCLogAllocLogInitData(void)
{
SCLogInitData *sc_lid = NULL;
if ( (sc_lid = SCMalloc(sizeof(SCLogInitData))) == NULL)
if ( (sc_lid = malloc(sizeof(SCLogInitData))) == NULL)
return NULL;
memset(sc_lid, 0, sizeof(SCLogInitData));
@ -1074,7 +1089,7 @@ void SCLogInitLogModule(SCLogInitData *sc_lid)
#endif /* OS_WIN32 */
/* sc_log_config is a global variable */
if ( (sc_log_config = SCMalloc(sizeof(SCLogConfig))) == NULL) {
if ( (sc_log_config = malloc(sizeof(SCLogConfig))) == NULL) {
SCLogError(SC_ERR_FATAL, "Fatal error encountered in SCLogInitLogModule. Exiting...");
exit(EXIT_FAILURE);
}
@ -1197,7 +1212,8 @@ void SCLogLoadConfig(void)
SCLogInitLogModule(sc_lid);
//exit(1);
/* \todo Can we free sc_lid now? */
if (sc_lid != NULL) SCFree(sc_lid);
if (sc_lid != NULL)
free(sc_lid);
}
/**
@ -1219,7 +1235,7 @@ void SCLogInitLogModuleIfEnvSet(void)
SCLogLevel log_level = SC_LOG_NOTSET;
/* sc_log_config is a global variable */
if ( (sc_log_config = SCMalloc(sizeof(SCLogConfig))) == NULL)
if ( (sc_log_config = malloc(sizeof(SCLogConfig))) == NULL)
return;
memset(sc_log_config, 0, sizeof(SCLogConfig));
sc_lc = sc_log_config;
@ -1345,7 +1361,7 @@ static char *SCLogGetLogFilename(char *filearg)
if (ConfGet("default-log-dir", &log_dir) != 1)
log_dir = DEFAULT_LOG_DIR;
log_filename = SCMalloc(PATH_MAX);
log_filename = malloc(PATH_MAX);
if (log_filename == NULL)
return NULL;
snprintf(log_filename, PATH_MAX, "%s/%s", log_dir, filearg);

@ -127,6 +127,7 @@
#else /* DBG_MEM_ALLOC */
#if 0
#define SCMalloc(a) ({ \
void *ptrmem = malloc(a); \
if (ptrmem == NULL) { \
@ -162,6 +163,11 @@
} \
(void*)ptrmem; \
})
#endif
#define SCMalloc malloc
#define SCRealloc realloc
#define SCCalloc calloc
#define SCStrdup strdup
#define SCFree(a) free((a))

Loading…
Cancel
Save