diff mbox series

[2/3] libsepol: fix potential memory leak in common_copy_callback

Message ID 20221205093644.703107-2-lujie54@huawei.com (mailing list archive)
State Changes Requested
Headers show
Series [1/3] libselinux: fix potential NULL reference and memory leak in audit2why | expand

Commit Message

Jie Lu Dec. 5, 2022, 9:36 a.m. UTC
In common_copy_callback(), destroy new_common->permissions when the function fails.

Signed-off-by: Jie Lu <lujie54@huawei.com>
---
 libsepol/src/expand.c | 1 +
 1 file changed, 1 insertion(+)

Comments

James Carter Dec. 16, 2022, 4:06 p.m. UTC | #1
On Mon, Dec 5, 2022 at 7:13 AM Jie Lu <lujie54@huawei.com> wrote:
>
> In common_copy_callback(), destroy new_common->permissions when the function fails.
>
> Signed-off-by: Jie Lu <lujie54@huawei.com>
> ---
>  libsepol/src/expand.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/libsepol/src/expand.c b/libsepol/src/expand.c
> index 8d19850e..b44cfd4f 100644
> --- a/libsepol/src/expand.c
> +++ b/libsepol/src/expand.c
> @@ -297,6 +297,7 @@ static int common_copy_callback(hashtab_key_t key, hashtab_datum_t datum,
>                            (hashtab_datum_t) new_common);
>         if (ret) {
>                 ERR(state->handle, "hashtab overflow");
> +               symtab_destroy(&new_common->permissions);
>                 free(new_common);
>                 free(new_id);
>                 return -1;

The call to hashtab_map() below this also needs similar cleanup if
there is an error. In fact, this whole function really needs common
cleanup code with a goto that code upon an error.

Thanks,
Jim


> --
> 2.27.0
>
diff mbox series

Patch

diff --git a/libsepol/src/expand.c b/libsepol/src/expand.c
index 8d19850e..b44cfd4f 100644
--- a/libsepol/src/expand.c
+++ b/libsepol/src/expand.c
@@ -297,6 +297,7 @@  static int common_copy_callback(hashtab_key_t key, hashtab_datum_t datum,
 			   (hashtab_datum_t) new_common);
 	if (ret) {
 		ERR(state->handle, "hashtab overflow");
+		symtab_destroy(&new_common->permissions);
 		free(new_common);
 		free(new_id);
 		return -1;