From 5dfda0c3c9a8f7f4456f6448536d04de021c791b Mon Sep 17 00:00:00 2001 From: "John Hodge (sonata)" Date: Sun, 11 Aug 2013 22:52:11 +0800 Subject: [PATCH] Modules/IPStack - Added some more buffer asserts --- KernelLand/Modules/IPStack/buffer.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/KernelLand/Modules/IPStack/buffer.c b/KernelLand/Modules/IPStack/buffer.c index b3c8093e..ac279761 100644 --- a/KernelLand/Modules/IPStack/buffer.c +++ b/KernelLand/Modules/IPStack/buffer.c @@ -119,6 +119,13 @@ size_t IPStack_Buffer_GetData(tIPStackBuffer *Buffer, void *Dest, size_t MaxByte for( int i = Buffer->nSubBuffers; i -- && rem_space != 0; ) { len = MIN(Buffer->SubBuffers[i].PreLength, rem_space); + #if !DISABLE_ASSERTS + if( !CheckMem(Buffer->SubBuffers[i].Data, len) ) { + Log_Error("IPStack", "Buffer pre %i invalid (%p+0x%x)", + i, Buffer->SubBuffers[i].Data, len); + return 0; + } + #endif memcpy(dest, Buffer->SubBuffers[i].Data, len @@ -132,10 +139,9 @@ size_t IPStack_Buffer_GetData(tIPStackBuffer *Buffer, void *Dest, size_t MaxByte continue ; len = MIN(Buffer->SubBuffers[i].PostLength, rem_space); - memcpy(dest, - (Uint8*)Buffer->SubBuffers[i].Data + Buffer->SubBuffers[i].PreLength, - len - ); + void *ptr = (Uint8*)Buffer->SubBuffers[i].Data + Buffer->SubBuffers[i].PreLength; + ASSERT( CheckMem(ptr, len) ); + memcpy(dest, ptr, len); dest += len; rem_space -= len; } -- 2.20.1