aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrumeet <yuuta@yuuta.moe>2021-06-06 23:46:38 -0700
committerTrumeet <yuuta@yuuta.moe>2021-06-06 23:46:38 -0700
commitb55296041b70c46c2949d8a176916e9ce8a4af7a (patch)
tree52af04bf61dd5aae77e7b3bf447bc1c9bd3cc8b8
parentaf3d8d2ffb895293dcb75b3736c6184a2f21c502 (diff)
downloadextmc-b55296041b70c46c2949d8a176916e9ce8a4af7a.tar
extmc-b55296041b70c46c2949d8a176916e9ce8a4af7a.tar.gz
extmc-b55296041b70c46c2949d8a176916e9ce8a4af7a.tar.bz2
extmc-b55296041b70c46c2949d8a176916e9ce8a4af7a.zip
fix: use address sanitizer to fix two memory issues
-rw-r--r--Makefile2
-rw-r--r--main.c3
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;