Skip to content

Commit

Permalink
Fix potential double-free in test3.c
Browse files Browse the repository at this point in the history
The pointer to newargv passed to poptParseArgvString() may not be
assigned to in case of an error, and it still may contain an address to
already freed memory from the previous for loop iteration.

To fix, add a return value check, similar to the one above it for the
out pointer.

Found by a static analyzer.
  • Loading branch information
dmnks authored and pmatilai committed May 17, 2024
1 parent 1e7bc38 commit cff3d07
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion tests/test3.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ int main (int argc, char **argv) {

printf ("single string: '%s'\n", out);

poptParseArgvString (out, &newargc, &newargv);
ret = poptParseArgvString (out, &newargc, &newargv);
if (ret != 0) {
printf ("cannot parse %s. ret=%d\n", out, ret);
continue;
}

printf ("popt array: size=%d\n", newargc);
for (j = 0; j < newargc; j++)
Expand Down

0 comments on commit cff3d07

Please sign in to comment.