In the function merge_state_with_log(), memory is allocated for the variable next_nodes when creating a union of the variables table_nodes and log_nodes. However, if next_state->entrance_nodes is NULL, then table_nodes becomes NULL and we still allocate memory to copy the content of log_nodes. This can cause a resource leak since we only free the memory for next_nodes if table_nodes isn't NULL. To prevent this, we need to check that next_state->entrance_nodes isn't NULL before allocating memory for the union. This issue has been fixed in the latest version of gnulib and I've backported this change to maintain consistency. This issue was found by a Coverity scan of GRUB2 under the CID 473887. Fixes: CID 473887 Signed-off-by: Alec Brown <alec.r.brown@oracle.com> Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
12 lines
493 B
Diff
12 lines
493 B
Diff
--- a/lib/regexec.c
|
|
+++ b/lib/regexec.c
|
|
@@ -2270,7 +2270,7 @@ merge_state_with_log (reg_errcode_t *err, re_match_context_t *mctx,
|
|
these destinations and the results of the transition table. */
|
|
pstate = mctx->state_log[cur_idx];
|
|
log_nodes = pstate->entrance_nodes;
|
|
- if (next_state != NULL)
|
|
+ if (next_state != NULL && next_state->entrance_nodes != NULL)
|
|
{
|
|
table_nodes = next_state->entrance_nodes;
|
|
*err = re_node_set_init_union (&next_nodes, table_nodes,
|