]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
Roll limit checks into INVALID_NDX macro, avoid overflow.
authorRoland McGrath <roland@redhat.com>
Sun, 9 Aug 2009 21:43:42 +0000 (14:43 -0700)
committerRoland McGrath <roland@redhat.com>
Sun, 9 Aug 2009 21:43:42 +0000 (14:43 -0700)
19 files changed:
libelf/gelf_getdyn.c
libelf/gelf_getlib.c
libelf/gelf_getmove.c
libelf/gelf_getrel.c
libelf/gelf_getrela.c
libelf/gelf_getsym.c
libelf/gelf_getsyminfo.c
libelf/gelf_getsymshndx.c
libelf/gelf_getversym.c
libelf/gelf_update_dyn.c
libelf/gelf_update_lib.c
libelf/gelf_update_move.c
libelf/gelf_update_rel.c
libelf/gelf_update_rela.c
libelf/gelf_update_sym.c
libelf/gelf_update_syminfo.c
libelf/gelf_update_symshndx.c
libelf/gelf_update_versym.c
libelf/libelfP.h

index bdf6476262a7f3ede137833cedae7fb71a54e4f8..195d2e0a5e8e92d15b98801f7320a9621bd0bf3f 100644 (file)
@@ -1,5 +1,5 @@
 /* Get information from dynamic table at the given index.
-   Copyright (C) 2000, 2001, 2002 Red Hat, Inc.
+   Copyright (C) 2000-2009 Red Hat, Inc.
    This file is part of Red Hat elfutils.
    Written by Ulrich Drepper <drepper@redhat.com>, 2000.
 
@@ -93,8 +93,7 @@ gelf_getdyn (data, ndx, dst)
         table entries has to be adopted.  The user better has provided
         a buffer where we can store the information.  While copying the
         data we are converting the format.  */
-      if (INVALID_NDX (ndx, Elf32_Dyn)
-         || unlikely ((ndx + 1) * sizeof (Elf32_Dyn) > data_scn->d.d_size))
+      if (INVALID_NDX (ndx, Elf32_Dyn, &data_scn->d))
        {
          __libelf_seterrno (ELF_E_INVALID_INDEX);
          goto out;
@@ -115,8 +114,7 @@ gelf_getdyn (data, ndx, dst)
 
       /* The data is already in the correct form.  Just make sure the
         index is OK.  */
-      if (INVALID_NDX (ndx, GElf_Dyn)
-         || unlikely ((ndx + 1) * sizeof (GElf_Dyn) > data_scn->d.d_size))
+      if (INVALID_NDX (ndx, GElf_Dyn, &data_scn->d))
        {
          __libelf_seterrno (ELF_E_INVALID_INDEX);
          goto out;
index eba1a3e9dcc2e6f936a3ee6b5a77695bd795aea1..3a110f8f92d26b36b4e36fdc3ceaffdfc363d5e6 100644 (file)
@@ -1,5 +1,5 @@
 /* Get library from table at the given index.
-   Copyright (C) 2004 Red Hat, Inc.
+   Copyright (C) 2004-2009 Red Hat, Inc.
    This file is part of Red Hat elfutils.
    Written by Ulrich Drepper <drepper@redhat.com>, 2004.
 
@@ -86,8 +86,7 @@ gelf_getlib (data, ndx, dst)
   /* The data is already in the correct form.  Just make sure the
      index is OK.  */
   GElf_Lib *result = NULL;
-  if (INVALID_NDX (ndx, GElf_Lib)
-      || unlikely ((ndx + 1) * sizeof (GElf_Lib) > data->d_size))
+  if (INVALID_NDX (ndx, GElf_Lib, data))
     __libelf_seterrno (ELF_E_INVALID_INDEX);
   else
     {
index 05f61b95c95bea5e382d5208b77301cb764cfa80..db36e9d5ebd29b7e72c62afdf823fc21ac0c117f 100644 (file)
@@ -1,5 +1,5 @@
 /* Get move structure at the given index.
-   Copyright (C) 2000, 2001, 2002 Red Hat, Inc.
+   Copyright (C) 2000-2009 Red Hat, Inc.
    This file is part of Red Hat elfutils.
    Written by Ulrich Drepper <drepper@redhat.com>, 2000.
 
@@ -83,8 +83,7 @@ gelf_getmove (data, ndx, dst)
 
   /* The data is already in the correct form.  Just make sure the
      index is OK.  */
-  if (INVALID_NDX (ndx, GElf_Move)
-      || unlikely ((ndx + 1) * sizeof (GElf_Move) > data->d_size))
+  if (INVALID_NDX (ndx, GElf_Move, data))
     {
       __libelf_seterrno (ELF_E_INVALID_INDEX);
       goto out;
index c809337903dc6996403585ed74b716f98c775753..bc90e60b13f16e8fd216457213e2dc6af3aba1d2 100644 (file)
@@ -1,5 +1,5 @@
 /* Get REL relocation information at given index.
-   Copyright (C) 2000, 2001, 2002 Red Hat, Inc.
+   Copyright (C) 2000-2009 Red Hat, Inc.
    This file is part of Red Hat elfutils.
    Written by Ulrich Drepper <drepper@redhat.com>, 2000.
 
@@ -87,8 +87,7 @@ gelf_getrel (data, ndx, dst)
   if (scn->elf->class == ELFCLASS32)
     {
       /* We have to convert the data.  */
-      if (INVALID_NDX (ndx, Elf32_Rel)
-         || unlikely ((ndx + 1) * sizeof (Elf32_Rel) > data_scn->d.d_size))
+      if (INVALID_NDX (ndx, Elf32_Rel, &data_scn->d))
        {
          __libelf_seterrno (ELF_E_INVALID_INDEX);
          result = NULL;
@@ -108,8 +107,7 @@ gelf_getrel (data, ndx, dst)
     {
       /* Simply copy the data after we made sure we are actually getting
         correct data.  */
-      if (INVALID_NDX (ndx, Elf64_Rel)
-         || unlikely ((ndx + 1) * sizeof (Elf64_Rel) > data_scn->d.d_size))
+      if (INVALID_NDX (ndx, Elf64_Rel, &data_scn->d))
        {
          __libelf_seterrno (ELF_E_INVALID_INDEX);
          result = NULL;
index 5d945bc67cf7ebe3aa2e2ddbe6a0cc7a4004d963..40da4e66c047c88d919f773a41cca6ba1a512da6 100644 (file)
@@ -1,5 +1,5 @@
 /* Get RELA relocation information at given index.
-   Copyright (C) 2000, 2001, 2002 Red Hat, Inc.
+   Copyright (C) 2000-2009 Red Hat, Inc.
    This file is part of Red Hat elfutils.
    Written by Ulrich Drepper <drepper@redhat.com>, 2000.
 
@@ -87,8 +87,7 @@ gelf_getrela (data, ndx, dst)
   if (scn->elf->class == ELFCLASS32)
     {
       /* We have to convert the data.  */
-      if (INVALID_NDX (ndx, Elf32_Rela)
-         || unlikely ((ndx + 1) * sizeof (Elf32_Rela) > data_scn->d.d_size))
+      if (INVALID_NDX (ndx, Elf32_Rela, &data_scn->d))
        {
          __libelf_seterrno (ELF_E_INVALID_INDEX);
          result = NULL;
@@ -109,8 +108,7 @@ gelf_getrela (data, ndx, dst)
     {
       /* Simply copy the data after we made sure we are actually getting
         correct data.  */
-      if (INVALID_NDX (ndx, Elf64_Rela)
-         || unlikely ((ndx + 1) * sizeof (Elf64_Rela) > data_scn->d.d_size))
+      if (INVALID_NDX (ndx, Elf64_Rela, &data_scn->d))
        {
          __libelf_seterrno (ELF_E_INVALID_INDEX);
          result = NULL;
index 1ec6321d62ad310b3ab37223be551346ee607f8f..77df2dc57497441f6f244398166ca3e14fff4943 100644 (file)
@@ -1,5 +1,5 @@
 /* Get symbol information from symbol table at the given index.
-   Copyright (C) 1999, 2000, 2001, 2002 Red Hat, Inc.
+   Copyright (C) 1999-2009 Red Hat, Inc.
    This file is part of Red Hat elfutils.
    Written by Ulrich Drepper <drepper@redhat.com>, 1999.
 
@@ -90,8 +90,7 @@ gelf_getsym (data, ndx, dst)
         table entries has to be adopted.  The user better has provided
         a buffer where we can store the information.  While copying the
         data we are converting the format.  */
-      if (INVALID_NDX (ndx, Elf32_Sym)
-         || unlikely ((ndx + 1) * sizeof (Elf32_Sym) > data->d_size))
+      if (INVALID_NDX (ndx, Elf32_Sym, data))
        {
          __libelf_seterrno (ELF_E_INVALID_INDEX);
          goto out;
@@ -120,8 +119,7 @@ gelf_getsym (data, ndx, dst)
 
       /* The data is already in the correct form.  Just make sure the
         index is OK.  */
-      if (INVALID_NDX (ndx, GElf_Sym)
-         || unlikely ((ndx + 1) * sizeof (GElf_Sym) > data->d_size))
+      if (INVALID_NDX (ndx, GElf_Sym, data))
        {
          __libelf_seterrno (ELF_E_INVALID_INDEX);
          goto out;
index f561cd451a1999a8c78107fc244e0140094f175b..03e32a17543d37558f8e4010246ca16d6de4afce 100644 (file)
@@ -1,5 +1,5 @@
 /* Get additional symbol information from symbol table at the given index.
-   Copyright (C) 2000, 2001, 2002 Red Hat, Inc.
+   Copyright (C) 2000-2009 Red Hat, Inc.
    This file is part of Red Hat elfutils.
    Written by Ulrich Drepper <drepper@redhat.com>, 2000.
 
@@ -84,8 +84,7 @@ gelf_getsyminfo (data, ndx, dst)
 
   /* The data is already in the correct form.  Just make sure the
      index is OK.  */
-  if (INVALID_NDX (ndx, GElf_Syminfo)
-      || unlikely ((ndx + 1) * sizeof (GElf_Syminfo) > data->d_size))
+  if (INVALID_NDX (ndx, GElf_Syminfo, data))
     {
       __libelf_seterrno (ELF_E_INVALID_INDEX);
       goto out;
index 33481c992bbb9ca6b1e2eadd00467488c985d701..c574a2a6171dcef3294c571dbb5b5917fc4d9a45 100644 (file)
@@ -1,6 +1,6 @@
 /* Get symbol information and separate section index from symbol table
    at the given index.
-   Copyright (C) 2000, 2001, 2002 Red Hat, Inc.
+   Copyright (C) 2000-2009 Red Hat, Inc.
    This file is part of Red Hat elfutils.
    Written by Ulrich Drepper <drepper@redhat.com>, 2000.
 
@@ -90,9 +90,7 @@ gelf_getsymshndx (symdata, shndxdata, ndx, dst, dstshndx)
      section index table.  */
   if (likely (shndxdata_scn != NULL))
     {
-      if (INVALID_NDX (ndx, Elf32_Word)
-         || unlikely ((ndx + 1) * sizeof (Elf32_Word)
-                      > shndxdata_scn->d.d_size))
+      if (INVALID_NDX (ndx, Elf32_Word, &shndxdata_scn->d))
        {
          __libelf_seterrno (ELF_E_INVALID_INDEX);
          goto out;
@@ -112,8 +110,7 @@ gelf_getsymshndx (symdata, shndxdata, ndx, dst, dstshndx)
         table entries has to be adopted.  The user better has provided
         a buffer where we can store the information.  While copying the
         data we are converting the format.  */
-      if (INVALID_NDX (ndx, Elf32_Sym)
-         || unlikely ((ndx + 1) * sizeof (Elf32_Sym) > symdata->d_size))
+      if (INVALID_NDX (ndx, Elf32_Sym, symdata))
        {
          __libelf_seterrno (ELF_E_INVALID_INDEX);
          goto out;
@@ -142,8 +139,7 @@ gelf_getsymshndx (symdata, shndxdata, ndx, dst, dstshndx)
 
       /* The data is already in the correct form.  Just make sure the
         index is OK.  */
-      if (INVALID_NDX (ndx, GElf_Sym)
-         || unlikely ((ndx + 1) * sizeof (GElf_Sym) > symdata->d_size))
+      if (INVALID_NDX (ndx, GElf_Sym, symdata))
        {
          __libelf_seterrno (ELF_E_INVALID_INDEX);
          goto out;
index 7097ca52cf02ba99fcc6c0439a4d2abd6597bd33..1abfce0b0ce7c3f937520900188b58ecb0c31db4 100644 (file)
@@ -1,5 +1,5 @@
 /* Get symbol version information at the given index.
-   Copyright (C) 1999, 2000, 2001, 2002 Red Hat, Inc.
+   Copyright (C) 1999-2009 Red Hat, Inc.
    This file is part of Red Hat elfutils.
    Written by Ulrich Drepper <drepper@redhat.com>, 1999.
 
@@ -92,8 +92,7 @@ gelf_getversym (data, ndx, dst)
 
   /* The data is already in the correct form.  Just make sure the
      index is OK.  */
-  if (INVALID_NDX (ndx, GElf_Versym)
-      || unlikely ((ndx + 1) * sizeof (GElf_Versym) > data->d_size))
+  if (INVALID_NDX (ndx, GElf_Versym, data))
     {
       __libelf_seterrno (ELF_E_INVALID_INDEX);
       result = NULL;
index 38d1076867e7081f7e3232bcc1f360a9047d08e9..08bd9bb3f911a47b8612f0f7b093063225d2336e 100644 (file)
@@ -1,5 +1,5 @@
 /* Update information in dynamic table at the given index.
-   Copyright (C) 2000, 2001, 2002 Red Hat, Inc.
+   Copyright (C) 2000-2009 Red Hat, Inc.
    This file is part of Red Hat elfutils.
    Written by Ulrich Drepper <drepper@redhat.com>, 2000.
 
@@ -96,8 +96,7 @@ gelf_update_dyn (data, ndx, src)
        }
 
       /* Check whether we have to resize the data buffer.  */
-      if (INVALID_NDX (ndx, Elf32_Dyn)
-         || unlikely ((ndx + 1) * sizeof (Elf32_Dyn) > data_scn->d.d_size))
+      if (INVALID_NDX (ndx, Elf32_Dyn, &data_scn->d))
        {
          __libelf_seterrno (ELF_E_INVALID_INDEX);
          goto out;
@@ -111,8 +110,7 @@ gelf_update_dyn (data, ndx, src)
   else
     {
       /* Check whether we have to resize the data buffer.  */
-      if (INVALID_NDX (ndx, Elf64_Dyn)
-         || unlikely ((ndx + 1) * sizeof (Elf64_Dyn) > data_scn->d.d_size))
+      if (INVALID_NDX (ndx, Elf64_Dyn, &data_scn->d))
        {
          __libelf_seterrno (ELF_E_INVALID_INDEX);
          goto out;
index 375d2381290737cdb9e63f490fe6c41286c0ad55..efbb9b6d359b50883559f38128d8b07275b23a29 100644 (file)
@@ -1,5 +1,5 @@
 /* Update library in table at the given index.
-   Copyright (C) 2004 Red Hat, Inc.
+   Copyright (C) 2004-2009 Red Hat, Inc.
    This file is part of Red Hat elfutils.
    Written by Ulrich Drepper <drepper@redhat.com>, 2004.
 
@@ -81,8 +81,7 @@ gelf_update_lib (data, ndx, src)
 
   /* Check whether we have to resize the data buffer.  */
   int result = 0;
-  if (INVALID_NDX (ndx, Elf64_Lib)
-      || unlikely ((ndx + 1) * sizeof (Elf64_Lib) > data_scn->d.d_size))
+  if (INVALID_NDX (ndx, Elf64_Lib, &data_scn->d))
     __libelf_seterrno (ELF_E_INVALID_INDEX);
   else
     {
index faadb0ba9025b01f8e761ab573d6a3e4683e2672..cb3d4ad3c30f1a3336cbcccaab4ea2a24732cff1 100644 (file)
@@ -1,5 +1,5 @@
 /* Update move structure at the given index.
-   Copyright (C) 2000, 2001, 2002 Red Hat, Inc.
+   Copyright (C) 2000-2009 Red Hat, Inc.
    This file is part of Red Hat elfutils.
    Written by Ulrich Drepper <drepper@redhat.com>, 2000.
 
@@ -75,8 +75,7 @@ gelf_update_move (data, ndx, src)
   assert (sizeof (GElf_Move) == sizeof (Elf64_Move));
 
   /* Check whether we have to resize the data buffer.  */
-  if (INVALID_NDX (ndx, GElf_Move)
-      || unlikely ((ndx + 1) * sizeof (GElf_Move) > data_scn->d.d_size))
+  if (INVALID_NDX (ndx, GElf_Move, &data_scn->d))
     {
       __libelf_seterrno (ELF_E_INVALID_INDEX);
       return 0;
index 1129185a0c422b12b1dcef42fdb2414978f7ab47..f966fc7428c3fc1129af4c7a300dafc2af6484cb 100644 (file)
@@ -1,5 +1,5 @@
 /* Update REL relocation information at given index.
-   Copyright (C) 2000, 2001, 2002 Red Hat, Inc.
+   Copyright (C) 2000-2009 Red Hat, Inc.
    This file is part of Red Hat elfutils.
    Written by Ulrich Drepper <drepper@redhat.com>, 2000.
 
@@ -93,8 +93,7 @@ gelf_update_rel (Elf_Data *dst, int ndx, GElf_Rel *src)
        }
 
       /* Check whether we have to resize the data buffer.  */
-      if (INVALID_NDX (ndx, Elf32_Rel)
-         || unlikely ((ndx + 1) * sizeof (Elf32_Rel) > data_scn->d.d_size))
+      if (INVALID_NDX (ndx, Elf32_Rel, &data_scn->d))
        {
          __libelf_seterrno (ELF_E_INVALID_INDEX);
          goto out;
@@ -109,8 +108,7 @@ gelf_update_rel (Elf_Data *dst, int ndx, GElf_Rel *src)
   else
     {
       /* Check whether we have to resize the data buffer.  */
-      if (INVALID_NDX (ndx, Elf64_Rel)
-         || unlikely ((ndx + 1) * sizeof (Elf64_Rel) > data_scn->d.d_size))
+      if (INVALID_NDX (ndx, Elf64_Rel, &data_scn->d))
        {
          __libelf_seterrno (ELF_E_INVALID_INDEX);
          goto out;
index b5c496569099f8c227582750b9abffa620cd419e..31234c170193e0addfaa4dad4b80f043f8e8346e 100644 (file)
@@ -1,5 +1,5 @@
 /* Update RELA relocation information at given index.
-   Copyright (C) 2000, 2001, 2002 Red Hat, Inc.
+   Copyright (C) 2000-2009 Red Hat, Inc.
    This file is part of Red Hat elfutils.
    Written by Ulrich Drepper <drepper@redhat.com>, 2000.
 
@@ -95,8 +95,7 @@ gelf_update_rela (Elf_Data *dst, int ndx, GElf_Rela *src)
        }
 
       /* Check whether we have to resize the data buffer.  */
-      if (INVALID_NDX (ndx, Elf32_Rela)
-         || unlikely ((ndx + 1) * sizeof (Elf32_Rela) > data_scn->d.d_size))
+      if (INVALID_NDX (ndx, Elf32_Rela, &data_scn->d))
        {
          __libelf_seterrno (ELF_E_INVALID_INDEX);
          goto out;
@@ -112,8 +111,7 @@ gelf_update_rela (Elf_Data *dst, int ndx, GElf_Rela *src)
   else
     {
       /* Check whether we have to resize the data buffer.  */
-      if (INVALID_NDX (ndx, Elf64_Rela)
-         || unlikely ((ndx + 1) * sizeof (Elf64_Rela) > data_scn->d.d_size))
+      if (INVALID_NDX (ndx, Elf64_Rela, &data_scn->d))
        {
          __libelf_seterrno (ELF_E_INVALID_INDEX);
          goto out;
index 16a6736264e1ea6f0f35bc95d8a9d0becdf3ae3c..960df2ec855a4b7af8847c78bd25e8bdb68003d8 100644 (file)
@@ -1,5 +1,5 @@
 /* Update symbol information in symbol table at the given index.
-   Copyright (C) 2000, 2001, 2002 Red Hat, Inc.
+   Copyright (C) 2000-2009 Red Hat, Inc.
    This file is part of Red Hat elfutils.
    Written by Ulrich Drepper <drepper@redhat.com>, 2000.
 
@@ -96,8 +96,7 @@ gelf_update_sym (data, ndx, src)
        }
 
       /* Check whether we have to resize the data buffer.  */
-      if (INVALID_NDX (ndx, Elf32_Sym)
-         || unlikely ((ndx + 1) * sizeof (Elf32_Sym) > data_scn->d.d_size))
+      if (INVALID_NDX (ndx, Elf32_Sym, &data_scn->d))
        {
          __libelf_seterrno (ELF_E_INVALID_INDEX);
          goto out;
@@ -120,8 +119,7 @@ gelf_update_sym (data, ndx, src)
   else
     {
       /* Check whether we have to resize the data buffer.  */
-      if (INVALID_NDX (ndx, Elf64_Sym)
-         || unlikely ((ndx + 1) * sizeof (Elf64_Sym) > data_scn->d.d_size))
+      if (INVALID_NDX (ndx, Elf64_Sym, &data_scn->d))
        {
          __libelf_seterrno (ELF_E_INVALID_INDEX);
          goto out;
index 659fa4f04439b4faf804f70b3b9846d93330b1bc..758d35bd7d43847cb119ae7e6e9e78a78cf81af8 100644 (file)
@@ -1,5 +1,5 @@
 /* Update additional symbol information in symbol table at the given index.
-   Copyright (C) 2000, 2001, 2002 Red Hat, Inc.
+   Copyright (C) 2000-2009 Red Hat, Inc.
    This file is part of Red Hat elfutils.
    Written by Ulrich Drepper <drepper@redhat.com>, 2000.
 
@@ -87,8 +87,7 @@ gelf_update_syminfo (data, ndx, src)
   rwlock_wrlock (scn->elf->lock);
 
   /* Check whether we have to resize the data buffer.  */
-  if (INVALID_NDX (ndx, GElf_Syminfo)
-      || unlikely ((ndx + 1) * sizeof (GElf_Syminfo) > data_scn->d.d_size))
+  if (INVALID_NDX (ndx, GElf_Syminfo, &data_scn->d))
     {
       __libelf_seterrno (ELF_E_INVALID_INDEX);
       goto out;
index e7d6fad71d15a1ea7a9fd61104e8ab35072ea4cb..0b8f7beafdf66115f143581395a00783eb60ad06 100644 (file)
@@ -1,6 +1,6 @@
 /* Update symbol information and section index in symbol table at the
    given index.
-   Copyright (C) 2000, 2001, 2002 Red Hat, Inc.
+   Copyright (C) 2000-2009 Red Hat, Inc.
    This file is part of Red Hat elfutils.
    Written by Ulrich Drepper <drepper@redhat.com>, 2000.
 
@@ -122,8 +122,7 @@ gelf_update_symshndx (symdata, shndxdata, ndx, src, srcshndx)
        }
 
       /* Check whether we have to resize the data buffer.  */
-      if (INVALID_NDX (ndx, Elf32_Sym)
-         || unlikely ((ndx + 1) * sizeof (Elf32_Sym) > symdata_scn->d.d_size))
+      if (INVALID_NDX (ndx, Elf32_Sym, &symdata_scn->d))
        {
          __libelf_seterrno (ELF_E_INVALID_INDEX);
          goto out;
@@ -146,8 +145,7 @@ gelf_update_symshndx (symdata, shndxdata, ndx, src, srcshndx)
   else
     {
       /* Check whether we have to resize the data buffer.  */
-      if (INVALID_NDX (ndx, Elf64_Sym)
-         || unlikely ((ndx + 1) * sizeof (Elf64_Sym) > symdata_scn->d.d_size))
+      if (INVALID_NDX (ndx, Elf64_Sym, &symdata_scn->d))
        {
          __libelf_seterrno (ELF_E_INVALID_INDEX);
          goto out;
index b69ec75b6f3bd05a49aa9a9d4d7101ae5e49901e..b4e9c17d27d906db7b95c1cbf82d1ab7dc6846fa 100644 (file)
@@ -1,5 +1,5 @@
 /* Update symbol version information.
-   Copyright (C) 2001, 2002 Red Hat, Inc.
+   Copyright (C) 2001-2009 Red Hat, Inc.
    This file is part of Red Hat elfutils.
    Written by Ulrich Drepper <drepper@redhat.com>, 2001.
 
@@ -75,8 +75,7 @@ gelf_update_versym (data, ndx, src)
   assert (sizeof (GElf_Versym) == sizeof (Elf64_Versym));
 
   /* Check whether we have to resize the data buffer.  */
-  if (INVALID_NDX (ndx, GElf_Versym)
-      || unlikely ((ndx + 1) * sizeof (GElf_Versym) > data_scn->d.d_size))
+  if (INVALID_NDX (ndx, GElf_Versym, &data_scn->d))
     {
       __libelf_seterrno (ELF_E_INVALID_INDEX);
       return 0;
index 2abf58cd1635c508a82d137316deeef51511cad8..ac90f39c0d62a6cb2974179d5db7e75d09b8cbe9 100644 (file)
@@ -606,13 +606,8 @@ extern uint32_t __libelf_crc32 (uint32_t crc, unsigned char *buf, size_t len)
 /* Align offset to 4 bytes as needed for note name and descriptor data.  */
 #define NOTE_ALIGN(n)  (((n) + 3) & -4U)
 
-/* Convenience macro.  Assumes int NDX and TYPE with size at least
-   2 bytes.  */
-#if SIZE_MAX > 4294967295U
-# define INVALID_NDX(ndx, type) unlikely (ndx < 0)
-#else
-# define INVALID_NDX(ndx, type) \
-  unlikely ((unsigned int) (ndx) >= SIZE_MAX / sizeof (type))
-#endif
+/* Convenience macro.  */
+#define INVALID_NDX(ndx, type, data) \
+  unlikely ((data)->d_size / sizeof (type) <= (unsigned int) (ndx))
 
 #endif  /* libelfP.h */