From b8e2178775a7cad40a117adc58e71b432c8481ff Mon Sep 17 00:00:00 2001 From: Scott Duensing Date: Wed, 23 Feb 2022 17:05:50 -0600 Subject: [PATCH] Added ASAN option to build. Fixed several stack bugs. --- client/client.pro | 6 ++++++ client/src/file.c | 1 + client/src/gui/image.c | 10 +++++----- client/src/login.c | 4 ++-- client/src/signup.c | 2 +- server/server.pro | 6 ++++++ server/src/client/file.c | 2 +- server/src/main.c | 2 +- shared/packet.c | 9 +-------- 9 files changed, 24 insertions(+), 18 deletions(-) diff --git a/client/client.pro b/client/client.pro index 06d1b94..fe4e7b7 100644 --- a/client/client.pro +++ b/client/client.pro @@ -21,6 +21,7 @@ TEMPLATE = app CONFIG -= qt +#CONFIG += ASAN DESTDIR = $$OUT_PWD/bin SHARED = $$PWD/../shared @@ -171,6 +172,11 @@ OTHER_FILES = \ $$DOS_SOURCES \ postBuild.sh +ASAN { + QMAKE_CFLAGS += -fsanitize=address -g + QMAKE_LFLAGS += -fsanitize=address -static-libasan +} + QMAKE_POST_LINK = $$PWD/postBuild.sh "$$PWD" "$$DESTDIR" DISTFILES += diff --git a/client/src/file.c b/client/src/file.c index 79e1253..3e6c15d 100644 --- a/client/src/file.c +++ b/client/src/file.c @@ -244,6 +244,7 @@ static void packetHandler(PacketDecodeDataT *packet) { _handle = NULL; // Update cache entry to include SHA. cacheEntryAdd(_currentSha256, cacheEntryNameGet(_file), _file); + DEL(_currentSha256); // Next file! fileCheckNext(); } else { diff --git a/client/src/gui/image.c b/client/src/gui/image.c index 811dc58..027ec47 100644 --- a/client/src/gui/image.c +++ b/client/src/gui/image.c @@ -26,7 +26,7 @@ #include "vesa.h" -static ImageT *imageNativeImageGet(unsigned char *raw, uint16_t x, uint16_t y); +static ImageT *imageNativeImageGet(unsigned char *raw, uint32_t x, uint32_t y); ImageT *imageAllocate(uint16_t w, uint16_t h) { @@ -118,9 +118,9 @@ uint8_t imageInfoGet(char *filename, uint16_t *width, uint16_t *height) { ImageT *imageLoad(char *filename) { - uint16_t x; - uint16_t y; - uint16_t n; + uint32_t x; + uint32_t y; + uint32_t n; unsigned char *raw; // Load image from disk @@ -131,7 +131,7 @@ ImageT *imageLoad(char *filename) { } -static ImageT *imageNativeImageGet(unsigned char *raw, uint16_t x, uint16_t y) { +static ImageT *imageNativeImageGet(unsigned char *raw, uint32_t x, uint32_t y) { uint32_t b; ImageT *image; diff --git a/client/src/login.c b/client/src/login.c index 3685102..26f254c 100644 --- a/client/src/login.c +++ b/client/src/login.c @@ -169,8 +169,8 @@ void loginShow() { static void packetHandler(PacketDecodeDataT *packet) { - char *packetData; - int8_t success; + char *packetData; + int32_t success; switch (packet->packetType) { case PACKET_TYPE_LOGIN_RESULT: diff --git a/client/src/signup.c b/client/src/signup.c index d8a2587..bfff892 100644 --- a/client/src/signup.c +++ b/client/src/signup.c @@ -130,7 +130,7 @@ static void btnSignUpClick(WidgetT *widget) { static void packetHandler(PacketDecodeDataT *packet) { - uint16_t length; + uint32_t length; char *packetData; // Reset timeout. diff --git a/server/server.pro b/server/server.pro index 3fb3a35..648fe47 100644 --- a/server/server.pro +++ b/server/server.pro @@ -22,6 +22,7 @@ CONFIG -= qt CONFIG += \ console \ c11 +# ASAN DESTDIR = $$OUT_PWD/bin SHARED = $$PWD/../shared @@ -101,3 +102,8 @@ LIBS = \ -ljson-c OTHER_FILES = + +ASAN { + QMAKE_CFLAGS += -fsanitize=address -g + QMAKE_LFLAGS += -fsanitize=address -static-libasan +} diff --git a/server/src/client/file.c b/server/src/client/file.c index 5f24a13..5a3f1b3 100644 --- a/server/src/client/file.c +++ b/server/src/client/file.c @@ -93,7 +93,7 @@ static void clientApiFileRequestCheck(ClientThreadT *client, PacketDecodeDataT * logWrite("[%s] [%s]\n\r", sha256, path); // Look up the entry and compare SHA256. - dbFileSha256Get(path, shaInDB, FILE_VIRTUAL_PATH_MAX); + dbFileSha256Get(path, shaInDB, 128); if (strcasecmp(sha256, shaInDB) == 0) { logWrite("File is current. Sending FILE_RESPONSE_OKAY.\n\r"); // File is already current on client. diff --git a/server/src/main.c b/server/src/main.c index b398f2a..e9de36d 100644 --- a/server/src/main.c +++ b/server/src/main.c @@ -37,7 +37,7 @@ uint8_t __restAvailable = 1; // "Config" items come from the INI file. "Settings" are from the database. static char *_configServer = NULL; -static uint16_t _configPort = 0; +static uint32_t _configPort = 0; static char *_configDatabase = NULL; static char *_configUser = NULL; static char *_configPassword = NULL; diff --git a/shared/packet.c b/shared/packet.c index 49e3b61..244e082 100644 --- a/shared/packet.c +++ b/shared/packet.c @@ -568,16 +568,9 @@ PacketThreadDataT *packetThreadDataCreate(void *senderData) { data = (PacketThreadDataT *)malloc(sizeof(PacketThreadDataT)); if (data) { - /* - data->sequence = 0; - data->lastRemoteSequence = 0; - data->historyPosition = 0; - */ - data->decodeQueueHead = 0; - data->decodeQueueTail = 0; + memset(data, 0, sizeof(PacketThreadDataT)); data->newPacket = 1; data->senderData = senderData; - data->aesContext = NULL; } return data;