Fix bad pointer / leak in regex code

This was found by Coverity (CID 1484201).  [BZ#24844]
* posix/regex_internal.c (create_cd_newstate): Fix use of bad
pointer and/or memory leak when storage is exhausted.
This commit is contained in:
Paul Eggert 2019-08-21 09:25:22 -07:00
parent 1baae4aa6f
commit 8a80ee5e2b
2 changed files with 14 additions and 3 deletions

View File

@ -1,3 +1,10 @@
2019-08-21 Paul Eggert <eggert@cs.ucla.edu>
Fix bad pointer / leak in regex code
This was found by Coverity (CID 1484201). [BZ#24844]
* posix/regex_internal.c (create_cd_newstate): Fix use of bad
pointer and/or memory leak when storage is exhausted.
2019-08-21 Zack Weinberg <zackw@panix.com> 2019-08-21 Zack Weinberg <zackw@panix.com>
* misc/syslog.c (__vsyslog_internal) * misc/syslog.c (__vsyslog_internal)

View File

@ -1716,15 +1716,19 @@ create_cd_newstate (const re_dfa_t *dfa, const re_node_set *nodes,
{ {
if (newstate->entrance_nodes == &newstate->nodes) if (newstate->entrance_nodes == &newstate->nodes)
{ {
newstate->entrance_nodes = re_malloc (re_node_set, 1); re_node_set *entrance_nodes = re_malloc (re_node_set, 1);
if (__glibc_unlikely (newstate->entrance_nodes == NULL)) if (__glibc_unlikely (entrance_nodes == NULL))
{ {
free_state (newstate); free_state (newstate);
return NULL; return NULL;
} }
newstate->entrance_nodes = entrance_nodes;
if (re_node_set_init_copy (newstate->entrance_nodes, nodes) if (re_node_set_init_copy (newstate->entrance_nodes, nodes)
!= REG_NOERROR) != REG_NOERROR)
return NULL; {
free_state (newstate);
return NULL;
}
nctx_nodes = 0; nctx_nodes = 0;
newstate->has_constraint = 1; newstate->has_constraint = 1;
} }