]> git.seodisparate.com - SimpleArchiver/commitdiff
Fix invalid memory usage bug causing invalid free
authorStephen Seo <seo.disparate@gmail.com>
Thu, 27 Jun 2024 04:28:53 +0000 (13:28 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Thu, 27 Jun 2024 04:28:53 +0000 (13:28 +0900)
realloc(...) was not used propertly. The number of items to be
reallocated was specified, but not the size of each item.

src/parser.c

index 28883d2ab52845e1055448ade8ccfdbf61d5a655..2e944a49a7972a077bbe2e69983ce6aa712f21d6 100644 (file)
@@ -116,7 +116,7 @@ int simple_archiver_parse_args(int argc, const char **argv,
 
         // TODO verify this is necessary, using different variables.
         ptr = out->working_files;
-        out->working_files = realloc(ptr, working_size + 1);
+        out->working_files = realloc(ptr, sizeof(char*) * (working_size + 1));
 
         // Set new actual last element to NULL.
         out->working_files[working_size] = NULL;