cleanup: Minor fixes in test code.

* Buffer overrun in auto test.
* Resource leak in AFL test code.
This commit is contained in:
iphydf 2021-12-07 15:27:27 +00:00
parent 01ea27085f
commit cdc0286050
No known key found for this signature in database
GPG Key ID: 3855DBA2D74403C9
2 changed files with 5 additions and 4 deletions

View File

@ -132,7 +132,7 @@ static void test_save_compatibility(const char *save_path)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
char base_path[4096]; char base_path[4096] = {0};
if (argc <= 1) { if (argc <= 1) {
const char *srcdir = getenv("srcdir"); const char *srcdir = getenv("srcdir");
@ -141,10 +141,10 @@ int main(int argc, char *argv[])
srcdir = "."; srcdir = ".";
} }
strcpy(base_path, srcdir); snprintf(base_path, sizeof(base_path), "%s", srcdir);
} else { } else {
strcpy(base_path, argv[1]); snprintf(base_path, sizeof(base_path), "%s", argv[1]);
base_path[strrchr(base_path, '/') - base_path] = 0; base_path[strrchr(base_path, '/') - base_path] = '\0';
} }
char save_path[4096 + sizeof(LOADED_SAVE_FILE)]; char save_path[4096 + sizeof(LOADED_SAVE_FILE)];

View File

@ -20,6 +20,7 @@ int main(int argc, char **argv)
size_t bytes_read = fread(buffer, filelen, 1, fileptr); size_t bytes_read = fread(buffer, filelen, 1, fileptr);
if (bytes_read != filelen) { if (bytes_read != filelen) {
fclose(fileptr);
free(buffer); free(buffer);
return -1; return -1;
} }