From b55296041b70c46c2949d8a176916e9ce8a4af7a Mon Sep 17 00:00:00 2001 From: Trumeet Date: Sun, 6 Jun 2021 23:46:38 -0700 Subject: fix: use address sanitizer to fix two memory issues --- Makefile | 2 +- main.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 4bc407f..2511216 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ OBJ=main.o thpool.o mcin.o plugins.o rcon_host.o rcon.o net.o plugin_registry.o BIN=extmc -debug: CFLAGS += -DCONTROL_SOCKET_PATH="\"./extmc.ctl\"" -g3 -O0 -rdynamic +debug: CFLAGS += -fsanitize=address -DCONTROL_SOCKET_PATH="\"./extmc.ctl\"" -g3 -O0 -rdynamic debug: $(BIN) release: CFLAGS += -DDISABLE_DEBUG diff --git a/main.c b/main.c index 8fbd6ab..608c10f 100644 --- a/main.c +++ b/main.c @@ -707,7 +707,7 @@ static int main_ctl(int argc, char **argv) length += strlen(argv[i]); if(i != argc - 1) length ++; } - char *dat = calloc(length, sizeof(char)); + char *dat = calloc(length + 1, sizeof(char)); strcpy(dat, ""); for(int i = 1; i < argc; i ++) { @@ -715,6 +715,7 @@ static int main_ctl(int argc, char **argv) if(i != argc - 1) strcat(dat, " "); } dprintf(fd, "%s", dat); + free(dat); ssize_t num_read; int arr_size = 1025; -- cgit v1.2.3