From 9e9b5c9cdaf840d6b9f2630ed0f6afe71570f7a1 Mon Sep 17 00:00:00 2001 From: Jordan Bancino Date: Thu, 23 Feb 2023 03:46:05 +0000 Subject: [PATCH] Fix a write-out-of-bounds error in Json. --- src/Json.c | 14 ++++++++++++++ src/Telodendria.c | 30 +++++++++++++++--------------- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/Json.c b/src/Json.c index f51fedd..e3311cb 100644 --- a/src/Json.c +++ b/src/Json.c @@ -424,6 +424,20 @@ JsonDecodeString(FILE * in) switch (c) { case '"': + if (len >= allocated) + { + char *tmp; + + allocated += 1; + tmp = Realloc(str, allocated * sizeof(char)); + if (!tmp) + { + Free(str); + return NULL; + } + + str = tmp; + } str[len] = '\0'; return str; break; diff --git a/src/Telodendria.c b/src/Telodendria.c index 339f68c..ddb84b1 100644 --- a/src/Telodendria.c +++ b/src/Telodendria.c @@ -80,6 +80,21 @@ const char "=======================================================" }; +static void +TelodendriaHexDump(size_t off, char *hexBuf, char *asciiBuf, void *args) +{ + LogConfig *lc = args; + + if (hexBuf && asciiBuf) + { + Log(lc, LOG_DEBUG, "%04x: %s | %s |", off, hexBuf, asciiBuf); + } + else + { + Log(lc, LOG_DEBUG, "%04x", off); + } +} + static void TelodendriaMemoryHook(MemoryAction a, MemoryInfo * i, void *args) { @@ -112,21 +127,6 @@ TelodendriaMemoryHook(MemoryAction a, MemoryInfo * i, void *args) MemoryInfoGetPointer(i)); } -static void -TelodendriaHexDump(size_t off, char *hexBuf, char *asciiBuf, void *args) -{ - LogConfig *lc = args; - - if (hexBuf && asciiBuf) - { - Log(lc, LOG_DEBUG, "%04x: %s | %s |", off, hexBuf, asciiBuf); - } - else - { - Log(lc, LOG_DEBUG, "%04x", off); - } -} - static void TelodendriaMemoryIterator(MemoryInfo * i, void *args) {