From 5b3923141f159e2c2640c976f0ac7fd91b346e73 Mon Sep 17 00:00:00 2001 From: fros4943 Date: Tue, 15 May 2007 18:13:32 +0000 Subject: [PATCH] added buffer overflow check --- platform/cooja/sys/log.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/platform/cooja/sys/log.c b/platform/cooja/sys/log.c index fc3a5902a..95fc81bd8 100644 --- a/platform/cooja/sys/log.c +++ b/platform/cooja/sys/log.c @@ -26,17 +26,18 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: log.c,v 1.1 2006/08/21 12:11:20 fros4943 Exp $ + * $Id: log.c,v 1.2 2007/05/15 18:13:32 fros4943 Exp $ */ #include "sys/log.h" #include "lib/simEnvChange.h" #include +#define MAX_LOG_LENGTH 1024 const struct simInterface simlog_interface; // COOJA variables -char simLoggedData[1024]; +char simLoggedData[MAX_LOG_LENGTH]; int simLoggedLength; char simLoggedFlag; @@ -53,6 +54,12 @@ log_message(const char *part1, const char *part2) void simlog(const char *message) { + if (simLoggedLength + strlen(message) > MAX_LOG_LENGTH) { + /* Dropping message due to buffer overflow */ + printf("Warning. Dropping log message due to buffer overflow\n"); + return; + } + memcpy(&simLoggedData[0] + simLoggedLength, &message[0], strlen(message)); simLoggedLength += strlen(message); simLoggedFlag = 1;