From cdc0286050e61a5d1a90b0fe4a8e4bf2a8d9d804 Mon Sep 17 00:00:00 2001 From: iphydf Date: Tue, 7 Dec 2021 15:27:27 +0000 Subject: [PATCH] cleanup: Minor fixes in test code. * Buffer overrun in auto test. * Resource leak in AFL test code. --- auto_tests/save_compatibility_test.c | 8 ++++---- testing/afl_toxsave.c | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/auto_tests/save_compatibility_test.c b/auto_tests/save_compatibility_test.c index 613c1a8e..437f3971 100644 --- a/auto_tests/save_compatibility_test.c +++ b/auto_tests/save_compatibility_test.c @@ -132,7 +132,7 @@ static void test_save_compatibility(const char *save_path) int main(int argc, char *argv[]) { - char base_path[4096]; + char base_path[4096] = {0}; if (argc <= 1) { const char *srcdir = getenv("srcdir"); @@ -141,10 +141,10 @@ int main(int argc, char *argv[]) srcdir = "."; } - strcpy(base_path, srcdir); + snprintf(base_path, sizeof(base_path), "%s", srcdir); } else { - strcpy(base_path, argv[1]); - base_path[strrchr(base_path, '/') - base_path] = 0; + snprintf(base_path, sizeof(base_path), "%s", argv[1]); + base_path[strrchr(base_path, '/') - base_path] = '\0'; } char save_path[4096 + sizeof(LOADED_SAVE_FILE)]; diff --git a/testing/afl_toxsave.c b/testing/afl_toxsave.c index 9f93074b..c254111b 100644 --- a/testing/afl_toxsave.c +++ b/testing/afl_toxsave.c @@ -20,6 +20,7 @@ int main(int argc, char **argv) size_t bytes_read = fread(buffer, filelen, 1, fileptr); if (bytes_read != filelen) { + fclose(fileptr); free(buffer); return -1; }