Bug 794: stream SACK list needs to respect memcap

pull/343/merge
Victor Julien 12 years ago
parent a4fca88ba7
commit b6995f7664

@ -24,6 +24,7 @@
*/ */
#include "suricata-common.h" #include "suricata-common.h"
#include "stream-tcp.h"
#include "stream-tcp-private.h" #include "stream-tcp-private.h"
#include "stream-tcp-sack.h" #include "stream-tcp-sack.h"
#include "util-unittest.h" #include "util-unittest.h"
@ -37,6 +38,23 @@ void StreamTcpSackPrintList(TcpStream *stream) {
} }
#endif /* DEBUG */ #endif /* DEBUG */
static StreamTcpSackRecord *StreamTcpSackRecordAlloc(void) {
if (StreamTcpCheckMemcap((uint32_t)sizeof(StreamTcpSackRecord)) == 0)
return NULL;
StreamTcpSackRecord *rec = SCMalloc(sizeof(*rec));
if (unlikely(rec == NULL))
return NULL;
StreamTcpIncrMemuse((uint64_t)sizeof(*rec));
return rec;
}
static void StreamTcpSackRecordFree(StreamTcpSackRecord *rec) {
SCFree(rec);
StreamTcpDecrMemuse((uint64_t)sizeof(*rec));
}
/** /**
* \brief insert a SACK range * \brief insert a SACK range
* *
@ -62,7 +80,7 @@ static int StreamTcpSackInsertRange(TcpStream *stream, uint32_t le, uint32_t re)
if (SEQ_LT(re, rec->le)) { if (SEQ_LT(re, rec->le)) {
SCLogDebug("SEQ_LT(re, rec->le)"); SCLogDebug("SEQ_LT(re, rec->le)");
// entirely before, prepend // entirely before, prepend
StreamTcpSackRecord *stsr = SCMalloc(sizeof(StreamTcpSackRecord)); StreamTcpSackRecord *stsr = StreamTcpSackRecordAlloc();
if (unlikely(stsr == NULL)) { if (unlikely(stsr == NULL)) {
SCReturnInt(-1); SCReturnInt(-1);
} }
@ -148,7 +166,7 @@ static int StreamTcpSackInsertRange(TcpStream *stream, uint32_t le, uint32_t re)
SCLogDebug("implied le > rec->re"); SCLogDebug("implied le > rec->re");
if (rec->next == NULL) { if (rec->next == NULL) {
SCLogDebug("rec->next == NULL"); SCLogDebug("rec->next == NULL");
StreamTcpSackRecord *stsr = SCMalloc(sizeof(StreamTcpSackRecord)); StreamTcpSackRecord *stsr = StreamTcpSackRecordAlloc();
if (unlikely(stsr == NULL)) { if (unlikely(stsr == NULL)) {
SCReturnInt(-1); SCReturnInt(-1);
} }
@ -163,7 +181,7 @@ static int StreamTcpSackInsertRange(TcpStream *stream, uint32_t le, uint32_t re)
SCLogDebug("implied rec->next != NULL"); SCLogDebug("implied rec->next != NULL");
if (SEQ_LT(le, rec->next->le) && SEQ_LT(re, rec->next->le)) { if (SEQ_LT(le, rec->next->le) && SEQ_LT(re, rec->next->le)) {
SCLogDebug("SEQ_LT(le, rec->next->le) && SEQ_LT(re, rec->next->le)"); SCLogDebug("SEQ_LT(le, rec->next->le) && SEQ_LT(re, rec->next->le)");
StreamTcpSackRecord *stsr = SCMalloc(sizeof(StreamTcpSackRecord)); StreamTcpSackRecord *stsr = StreamTcpSackRecordAlloc();
if (unlikely(stsr == NULL)) { if (unlikely(stsr == NULL)) {
SCReturnInt(-1); SCReturnInt(-1);
} }
@ -174,7 +192,7 @@ static int StreamTcpSackInsertRange(TcpStream *stream, uint32_t le, uint32_t re)
} else if (SEQ_LT(le, rec->next->le) && SEQ_GEQ(re, rec->next->le)) { } else if (SEQ_LT(le, rec->next->le) && SEQ_GEQ(re, rec->next->le)) {
SCLogDebug("SEQ_LT(le, rec->next->le) && SEQ_GEQ(re, rec->next->le)"); SCLogDebug("SEQ_LT(le, rec->next->le) && SEQ_GEQ(re, rec->next->le)");
StreamTcpSackRecord *stsr = SCMalloc(sizeof(StreamTcpSackRecord)); StreamTcpSackRecord *stsr = StreamTcpSackRecordAlloc();
if (unlikely(stsr == NULL)) { if (unlikely(stsr == NULL)) {
SCReturnInt(-1); SCReturnInt(-1);
} }
@ -191,7 +209,7 @@ static int StreamTcpSackInsertRange(TcpStream *stream, uint32_t le, uint32_t re)
} }
} else { } else {
SCLogDebug("implied empty list"); SCLogDebug("implied empty list");
StreamTcpSackRecord *stsr = SCMalloc(sizeof(StreamTcpSackRecord)); StreamTcpSackRecord *stsr = StreamTcpSackRecordAlloc();
if (unlikely(stsr == NULL)) { if (unlikely(stsr == NULL)) {
SCReturnInt(-1); SCReturnInt(-1);
} }
@ -307,7 +325,7 @@ void StreamTcpSackFreeList(TcpStream *stream) {
while (rec != NULL) { while (rec != NULL) {
next = rec->next; next = rec->next;
SCFree(rec); StreamTcpSackRecordFree(rec);
rec = next; rec = next;
} }

Loading…
Cancel
Save