Re: [PATCH] libsepol: Turn assert into error in type_set_expand()

Stephen Smalley <[email protected]> Wed, 29 Jul 2026 16:00:01 -0400
Newsgroups org.kernel.vger.selinux
Message-ID <CAEjxPJ6J=ArpCwLAaCed7Gn2K4nDJODLcSwZ5orJT7zw4HyiQg@mail.gmail.com>
On Wed, Jul 29, 2026 at 3:37 PM James Carter <[email protected]> wrote:
>
> The assertion in function type_set_expand() can only be violated by
> a malformed policy. Since it is called before the policy has been
> validated just return an error.
>
> Signed-off-by: James Carter <[email protected]>
> ---
>  libsepol/src/expand.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/libsepol/src/expand.c b/libsepol/src/expand.c
> index 8d7fe519..19b5fdcc 100644
> --- a/libsepol/src/expand.c
> +++ b/libsepol/src/expand.c
> @@ -2827,8 +2827,8 @@ int type_set_expand(type_set_t *set, ebitmap_t *t, policydb_t *p,
>                 for (i = 0; i < p->p_types.nprim; i++) {
>                         if (p->type_val_to_struct[i] &&
>                             p->type_val_to_struct[i]->flavor == TYPE_ATTRIB) {
> -                               assert(!ebitmap_get_bit(t, i));
> -                               continue;
> +                               if (ebitmap_get_bit(t, i))
> +                                       goto err_neg;

Why did you drop the continue; in the non-error path?

>                         }
>                         if (ebitmap_get_bit(t, i)) {
>                                 if (ebitmap_set_bit(t, i, 0))
> --
> 2.55.0
>