]> git.tuebingen.mpg.de Git - lopsub.git/commit - lopsub.c
lopsub.c: Fix a NULL pointer dereference and a double free.
authorAndre Noll <maan@tuebingen.mpg.de>
Fri, 21 Apr 2017 22:02:05 +0000 (00:02 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Wed, 12 Jul 2017 12:14:37 +0000 (14:14 +0200)
commita1a679403ccafb26fe91c52cc4065e9e6524c09d
treedc283ab72fc56f7d6bbb5a88e4e5504f52a8d504
parente5b276f1a15604f1c7efe754074a86fabbb6bf6f
lopsub.c: Fix a NULL pointer dereference and a double free.

The error path of lls_deserialize_parse_result() has two issues:

* if the allocation of lor->value fails, we dereference a NULL pointer
in the cleanup part after label free_options because in

free(lor->value[j].string_val);

lor->value is NULL.

* if the strdup() for a multiple option fails in the inner loop, we
deallocate all previously allocated strings, jump to the free_options
label, and attempt to free the same values again.

The root of both bugs is that we start the cleanup in the error case
using the current value of the outer loop index i. The fix is to
perform cleanup of the allocated memory for option i already in the
allocation loop and let the cleanup loop iterate downwards from i - 1.

This bug was found by the clang static analyzer.
lopsub.c