Hi Mark,

LGTM.

Aaron

On Sun, Nov 8, 2026 at 7:09 PM Mark Wielaard <[email protected]> wrote:
>
> gelf_getauxv and gelf_update_auxv check whether the given ndx fits
> checking whether the multiplication of the ndx by the sizeof type is
> larger than d_size. But these multiplications can overflow. Use the
> INVALID_NDX macro instead.
>
>         * libelf/gelf_getauxv.c (gelf_getauxv): Check using INVALID_NDX.
>         * libelf/gelf_update_auxv.c (gelf_update_auxv): Likewise.
>
> Signed-off-by: Mark Wielaard <[email protected]>
> ---
>  libelf/gelf_getauxv.c     | 4 ++--
>  libelf/gelf_update_auxv.c | 4 ++--
>  2 files changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/libelf/gelf_getauxv.c b/libelf/gelf_getauxv.c
> index 405ec6465c83..d3a178b5fc46 100644
> --- a/libelf/gelf_getauxv.c
> +++ b/libelf/gelf_getauxv.c
> @@ -67,7 +67,7 @@ gelf_getauxv (Elf_Data *data, int ndx, GElf_auxv_t *dst)
>          entries has to be converted.  The user better have provided a
>          buffer where we can store the information.  While copying the data
>          we convert the format.  */
> -      if (unlikely ((ndx + 1) * sizeof (Elf32_auxv_t) > data_scn->d.d_size))
> +      if (INVALID_NDX (ndx, Elf32_auxv_t, &data_scn->d))
>         {
>           __libelf_seterrno (ELF_E_INVALID_INDEX);
>           goto out;
> @@ -87,7 +87,7 @@ gelf_getauxv (Elf_Data *data, int ndx, GElf_auxv_t *dst)
>
>        /* The data is already in the correct form.  Just make sure the
>          index is OK.  */
> -      if (unlikely ((ndx + 1) * sizeof (GElf_auxv_t) > data_scn->d.d_size))
> +      if (INVALID_NDX (ndx, GElf_auxv_t, &data_scn->d))
>         {
>           __libelf_seterrno (ELF_E_INVALID_INDEX);
>           goto out;
> diff --git a/libelf/gelf_update_auxv.c b/libelf/gelf_update_auxv.c
> index e4e5229c623f..1254ef466b36 100644
> --- a/libelf/gelf_update_auxv.c
> +++ b/libelf/gelf_update_auxv.c
> @@ -76,7 +76,7 @@ gelf_update_auxv (Elf_Data *data, int ndx, GElf_auxv_t *src)
>         }
>
>        /* Check whether we have to resize the data buffer.  */
> -      if (unlikely ((ndx + 1) * sizeof (Elf32_auxv_t) > data_scn->d.d_size))
> +      if (INVALID_NDX (ndx, Elf32_auxv_t, &data_scn->d))
>         {
>           __libelf_seterrno (ELF_E_INVALID_INDEX);
>           goto out;
> @@ -90,7 +90,7 @@ gelf_update_auxv (Elf_Data *data, int ndx, GElf_auxv_t *src)
>    else
>      {
>        /* Check whether we have to resize the data buffer.  */
> -      if (unlikely ((ndx + 1) * sizeof (Elf64_auxv_t) > data_scn->d.d_size))
> +      if (INVALID_NDX (ndx, Elf64_auxv_t, &data_scn->d))
>         {
>           __libelf_seterrno (ELF_E_INVALID_INDEX);
>           goto out;
> --
> 2.56.0
>

Reply via email to