From cd1b1cce5d0a10b05979f794926717bae1b14520 Mon Sep 17 00:00:00 2001 From: Tomas Halman Date: Jul 27 2021 14:06:07 +0000 Subject: [PATCH 1/3] lib/user.c: memory leak in lu_dispatch The tmp variable is allocated and not released when we return directly from switch. This fix removes g_return_val_if_fail call and we break out from switch statement the same way as it is done in other cases. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1938802 --- diff --git a/lib/user.c b/lib/user.c index 2500565..00b9863 100644 --- a/lib/user.c +++ b/lib/user.c @@ -986,7 +986,8 @@ lu_dispatch(struct lu_context *context, case user_default: case group_default: /* Make sure we have both name and boolean here. */ - g_return_val_if_fail(sdata != NULL, FALSE); + if (sdata == NULL) + break; /* Run the checks and preps. */ if (run_list(context, context->create_module_names, logic_and, id, @@ -1065,7 +1066,8 @@ lu_dispatch(struct lu_context *context, case user_setpass: case group_setpass: /* Make sure we have a valid password. */ - g_return_val_if_fail(sdata != NULL, FALSE); + if (sdata == NULL) + break; /* no break: fall through */ case user_removepass: case group_removepass: @@ -1094,7 +1096,8 @@ lu_dispatch(struct lu_context *context, case users_enumerate_by_group: case groups_enumerate_by_user: /* Make sure we have both name and ID here. */ - g_return_val_if_fail(sdata != NULL, FALSE); + if (sdata == NULL) + break; if (id == users_enumerate_by_group) ldata = convert_group_name_to_id(context, sdata, error); From 14cca137eae87e34b3e02351195fda9056577e9e Mon Sep 17 00:00:00 2001 From: Tomas Halman Date: Jul 27 2021 15:12:21 +0000 Subject: [PATCH 2/3] Use assert instead if --- diff --git a/lib/user.c b/lib/user.c index 00b9863..97dce6d 100644 --- a/lib/user.c +++ b/lib/user.c @@ -986,8 +986,7 @@ lu_dispatch(struct lu_context *context, case user_default: case group_default: /* Make sure we have both name and boolean here. */ - if (sdata == NULL) - break; + g_assert(sdata != NULL); /* Run the checks and preps. */ if (run_list(context, context->create_module_names, logic_and, id, @@ -1066,8 +1065,7 @@ lu_dispatch(struct lu_context *context, case user_setpass: case group_setpass: /* Make sure we have a valid password. */ - if (sdata == NULL) - break; + g_assert(sdata != NULL); /* no break: fall through */ case user_removepass: case group_removepass: @@ -1096,8 +1094,7 @@ lu_dispatch(struct lu_context *context, case users_enumerate_by_group: case groups_enumerate_by_user: /* Make sure we have both name and ID here. */ - if (sdata == NULL) - break; + g_assert(sdata != NULL); if (id == users_enumerate_by_group) ldata = convert_group_name_to_id(context, sdata, error); From aba17dd606e02467a8f7c7d76d26a5b783520e2d Mon Sep 17 00:00:00 2001 From: Tomas Halman Date: Jul 29 2021 09:50:29 +0000 Subject: [PATCH 3/3] Use g_warn_if_fail --- diff --git a/lib/user.c b/lib/user.c index 97dce6d..dd20918 100644 --- a/lib/user.c +++ b/lib/user.c @@ -971,7 +971,9 @@ lu_dispatch(struct lu_context *context, case user_lookup_name: case group_lookup_name: /* Make sure data items are right for this call. */ - g_assert(sdata != NULL); + g_warn_if_fail(sdata != NULL); + if (sdata == NULL) + break; /* Run the list. */ if (run_list(context, context->module_names, logic_or, id, sdata, LU_VALUE_INVALID_ID, tmp, &scratch, @@ -986,7 +988,9 @@ lu_dispatch(struct lu_context *context, case user_default: case group_default: /* Make sure we have both name and boolean here. */ - g_assert(sdata != NULL); + g_warn_if_fail(sdata != NULL); + if (sdata == NULL) + break; /* Run the checks and preps. */ if (run_list(context, context->create_module_names, logic_and, id, @@ -1065,7 +1069,9 @@ lu_dispatch(struct lu_context *context, case user_setpass: case group_setpass: /* Make sure we have a valid password. */ - g_assert(sdata != NULL); + g_warn_if_fail(sdata != NULL); + if (sdata == NULL) + break; /* no break: fall through */ case user_removepass: case group_removepass: