libsemanage: clear freed keys during component merges
Stephen Smalley
maintainerPATCH 1/1 libsemanage: clear freed keys during component merges
clear_obsolete() and load_records() free the current key after each successful iteration but leave the pointer unchanged. If extracting the next key fails, the error path frees the previous key again. Record key constructors such as sepol_bool_key_create() leave their output untouched on allocation failure, so cleanup accesses freed memory instead of simply returning the merge error.
Reset each key pointer to NULL immediately after freeing it. This keeps cleanup valid when a later extraction fails without changing which records are merged or how errors propagate to the caller.
--- libsemanage/src/policy_components.c | 2 ++ 1 file changed, 2 insertions(+)
libsemanage/src/policy_components.c +2 -0
@@ -44,6 +44,7 @@ static int clear_obsolete(semanage_handle_t *handle, record_t **records, } rtable->key_free (key); + key =NULL ; }return STATUS_SUCCESS ;
@@ -81,6 +82,7 @@ static int load_records(semanage_handle_t *handle, dbase_config_t *dst, goto err; rtable->key_free (rkey); + rkey =NULL ; }return STATUS_SUCCESS ;
Signature · 1 line
2.56.0
Stephen Smalley
maintainerQuoted 8 lines · Stephen Smalley
clear_obsolete()andload_records()free the current key after each successful iteration but leave the pointer unchanged. If extracting the next key fails, the error path frees the previous key again. Record key constructors such assepol_bool_key_create()leave their output untouched on allocation failure, so cleanup accesses freed memory instead of simply returning the merge error.
Quoted 5 lines
Reset each key pointer to NULL immediately after freeing it. This keeps cleanup valid when a later extraction fails without changing which records are merged or how errors propagate to the caller.
Signed-off-by Stephen Smalley <[email protected]>
This has been merged.