update libelf from elftoolchain r3717 to r3833 no need for a crank according to src/lib/check_sym
------------------------------------------------------------------------ r3833 | jkoshy | 2020-03-02 18:19:04 +1100 (Mon, 02 Mar 2020) | 4 lines Minor: add comments. Ticket: [#584] ------------------------------------------------------------------------ r3764 | emaste | 2019-06-29 07:44:46 +1000 (Sat, 29 Jun 2019) | 3 lines libelf: add config for RISC-V ISA Obtained from FreeBSD r294664 by br. ------------------------------------------------------------------------ r3763 | emaste | 2019-06-29 07:43:27 +1000 (Sat, 29 Jun 2019) | 5 lines libelf: assert that msz is non-zero Reported by FreeBSD Coverity, CID 976023 Obtained from FreeBSD r316685 by emaste. ------------------------------------------------------------------------ r3743 | jkoshy | 2019-06-13 05:36:30 +1000 (Thu, 13 Jun 2019) | 3 lines Incorporate manual page fixes from OpenBSD. Submitted by: Sunil Nimmagadda ------------------------------------------------------------------------ r3740 | jkoshy | 2019-05-06 15:18:34 +1000 (Mon, 06 May 2019) | 2 lines Verify that only one of the LIBELF_F_RAWFILE_{MALLOC,MMAP} flags is set on an ELF descriptor. ------------------------------------------------------------------------ r3739 | jkoshy | 2019-05-06 15:18:15 +1000 (Mon, 06 May 2019) | 3 lines Bug fix: use integer literals of the correct size. Found by: Coverity Scan ------------------------------------------------------------------------ r3738 | jkoshy | 2019-05-06 07:49:06 +1000 (Mon, 06 May 2019) | 3 lines Improve an internal API: a return type of 'void' would be a better fit for an internal function that never returns a usable value. ------------------------------------------------------------------------ r3737 | jkoshy | 2019-05-06 00:49:50 +1000 (Mon, 06 May 2019) | 3 lines Eliminate an always true sub-expression. Pointed out by: Sunil Nimmagadda ------------------------------------------------------------------------ r3736 | jkoshy | 2019-05-05 23:22:07 +1000 (Sun, 05 May 2019) | 3 lines Add a few assertions. Submitted by: Sunil Nimmagadda ------------------------------------------------------------------------ r3734 | jkoshy | 2019-04-23 00:10:49 +1000 (Tue, 23 Apr 2019) | 2 lines Document the additional errors possible for the APIs updated by revision r3732. ------------------------------------------------------------------------ r3732 | jkoshy | 2019-04-22 21:08:38 +1000 (Mon, 22 Apr 2019) | 4 lines Handle error returns from the _libelf_msize() helper function consistently. Pointed out by: Sunil Nimmagadda on -developers ------------------------------------------------------------------------ Index: _libelf.h =================================================================== RCS file: /cvs/src/lib/libelf/_libelf.h,v retrieving revision 1.2 diff -u -p -r1.2 _libelf.h --- _libelf.h 19 Mar 2019 02:31:35 -0000 1.2 +++ _libelf.h 11 May 2020 06:10:12 -0000 @@ -226,7 +226,7 @@ size_t _libelf_msize(Elf_Type _t, int _e void *_libelf_newphdr(Elf *_e, int _elfclass, size_t _count); Elf *_libelf_open_object(int _fd, Elf_Cmd _c, int _reporterror); struct _Libelf_Data *_libelf_release_data(struct _Libelf_Data *_d); -Elf *_libelf_release_elf(Elf *_e); +void _libelf_release_elf(Elf *_e); Elf_Scn *_libelf_release_scn(Elf_Scn *_s); int _libelf_setphnum(Elf *_e, void *_eh, int _elfclass, size_t _phnum); int _libelf_setshnum(Elf *_e, void *_eh, int _elfclass, size_t _shnum); Index: _libelf_config.h =================================================================== RCS file: /cvs/src/lib/libelf/_libelf_config.h,v retrieving revision 1.1 diff -u -p -r1.1 _libelf_config.h --- _libelf_config.h 1 Feb 2019 05:27:37 -0000 1.1 +++ _libelf_config.h 11 May 2020 06:10:12 -0000 @@ -103,6 +103,12 @@ #define LIBELF_BYTEORDER ELFDATA2LSB #define LIBELF_CLASS ELFCLASS64 +#elif defined(__riscv64) + +#define LIBELF_ARCH EM_RISCV +#define LIBELF_BYTEORDER ELFDATA2LSB +#define LIBELF_CLASS ELFCLASS64 + #elif defined(__sparc__) #define LIBELF_ARCH EM_SPARCV9 Index: elf.3 =================================================================== RCS file: /cvs/src/lib/libelf/elf.3,v retrieving revision 1.4 diff -u -p -r1.4 elf.3 --- elf.3 11 Jun 2019 18:38:46 -0000 1.4 +++ elf.3 11 May 2020 06:10:12 -0000 @@ -23,7 +23,7 @@ .\" .\" $Id: elf.3,v 1.4 2019/06/11 18:38:46 schwarze Exp $ .\" -.Dd February 5, 2019 +.Dd June 12, 2019 .Dt ELF 3 .Os .Sh NAME Index: elf_data.c =================================================================== RCS file: /cvs/src/lib/libelf/elf_data.c,v retrieving revision 1.2 diff -u -p -r1.2 elf_data.c --- elf_data.c 19 Mar 2019 02:31:35 -0000 1.2 +++ elf_data.c 11 May 2020 06:10:12 -0000 @@ -118,7 +118,8 @@ elf_getdata(Elf_Scn *s, Elf_Data *ed) count = (size_t) (sh_size / fsz); - msz = _libelf_msize(elftype, elfclass, e->e_version); + if ((msz = _libelf_msize(elftype, elfclass, e->e_version)) == 0) + return (NULL); if (count > 0 && msz > SIZE_MAX / count) { LIBELF_SET_ERROR(RANGE, 0); Index: elf_end.c =================================================================== RCS file: /cvs/src/lib/libelf/elf_end.c,v retrieving revision 1.2 diff -u -p -r1.2 elf_end.c --- elf_end.c 19 Mar 2019 02:31:35 -0000 1.2 +++ elf_end.c 11 May 2020 06:10:12 -0000 @@ -88,7 +88,7 @@ elf_end(Elf *e) sv = e; if ((e = e->e_parent) != NULL) e->e_u.e_ar.e_nchildren--; - sv = _libelf_release_elf(sv); + _libelf_release_elf(sv); } return (0); Index: elf_flagdata.3 =================================================================== RCS file: /cvs/src/lib/libelf/elf_flagdata.3,v retrieving revision 1.2 diff -u -p -r1.2 elf_flagdata.3 --- elf_flagdata.3 11 Jun 2019 18:30:31 -0000 1.2 +++ elf_flagdata.3 11 May 2020 06:10:12 -0000 @@ -23,7 +23,7 @@ .\" .\" $Id: elf_flagdata.3,v 1.2 2019/06/11 18:30:31 schwarze Exp $ .\" -.Dd December 3, 2011 +.Dd June 12, 2019 .Dt ELF_FLAGDATA 3 .Os .Sh NAME Index: elf_getdata.3 =================================================================== RCS file: /cvs/src/lib/libelf/elf_getdata.3,v retrieving revision 1.1 diff -u -p -r1.1 elf_getdata.3 --- elf_getdata.3 1 Feb 2019 05:27:37 -0000 1.1 +++ elf_getdata.3 11 May 2020 06:10:12 -0000 @@ -23,7 +23,7 @@ .\" .\" $Id: elf_getdata.3,v 1.1 2019/02/01 05:27:37 jsg Exp $ .\" -.Dd January 26, 2011 +.Dd April 22, 2019 .Dt ELF_GETDATA 3 .Os .Sh NAME @@ -214,7 +214,12 @@ is incorrect. .It Bq Er ELF_E_UNIMPL The section type associated with section .Ar scn -is currently unsupported by the library. +is not supported. +.It Bq Er ELF_E_VERSION +Section +.Ar scn +was associated with an ELF object with an unsupported +version. .El .Sh SEE ALSO .Xr elf 3 , Index: elf_open.3 =================================================================== RCS file: /cvs/src/lib/libelf/elf_open.3,v retrieving revision 1.2 diff -u -p -r1.2 elf_open.3 --- elf_open.3 11 Jun 2019 18:30:31 -0000 1.2 +++ elf_open.3 11 May 2020 06:10:12 -0000 @@ -23,7 +23,7 @@ .\" .\" $Id: elf_open.3,v 1.2 2019/06/11 18:30:31 schwarze Exp $ .\" -.Dd May 31, 2012 +.Dd June 12, 2019 .Dt ELF_OPEN 3 .Os .Sh NAME Index: elf_update.3 =================================================================== RCS file: /cvs/src/lib/libelf/elf_update.3,v retrieving revision 1.1 diff -u -p -r1.1 elf_update.3 --- elf_update.3 1 Feb 2019 05:27:37 -0000 1.1 +++ elf_update.3 11 May 2020 06:10:12 -0000 @@ -23,7 +23,7 @@ .\" .\" $Id: elf_update.3,v 1.1 2019/02/01 05:27:37 jsg Exp $ .\" -.Dd August 14, 2011 +.Dd April 22, 2019 .Dt ELF_UPDATE 3 .Os .Sh NAME @@ -345,6 +345,10 @@ operation was requested after a prior ca disassociated the ELF descriptor .Ar elf from its underlying file. +.It Bq Er ELF_E_UNIMPL +Argument +.Ar elf +contained a section with an unsupported ELF type. .It Bq Er ELF_E_VERSION Argument .Ar elf Index: elf_update.c =================================================================== RCS file: /cvs/src/lib/libelf/elf_update.c,v retrieving revision 1.2 diff -u -p -r1.2 elf_update.c --- elf_update.c 19 Mar 2019 02:31:35 -0000 1.2 +++ elf_update.c 11 May 2020 06:10:12 -0000 @@ -222,10 +222,16 @@ _libelf_compute_section_extents(Elf *e, } /* + * The data buffer's ELF type, ELF class and ELF version + * should be supported. + */ + if ((msz = _libelf_msize(d->d_type, ec, e->e_version)) == 0) + return (0); + + /* * The buffer's size should be a multiple of the * memory size of the underlying type. */ - msz = _libelf_msize(d->d_type, ec, e->e_version); if (d->d_size % msz) { LIBELF_SET_ERROR(DATA, 0); return (0); @@ -800,7 +806,8 @@ _libelf_write_scn(Elf *e, unsigned char d = &ld->d_data; - msz = _libelf_msize(d->d_type, ec, e->e_version); + if ((msz = _libelf_msize(d->d_type, ec, e->e_version)) == 0) + return ((off_t) -1); if ((uint64_t) rc < sh_off + d->d_off) (void) memset(nf + rc, @@ -812,6 +819,7 @@ _libelf_write_scn(Elf *e, unsigned char assert(d->d_buf != NULL); assert(d->d_version == e->e_version); assert(d->d_size % msz == 0); + assert(msz != 0); nobjects = (size_t) (d->d_size / msz); @@ -851,7 +859,8 @@ _libelf_write_ehdr(Elf *e, unsigned char assert(ehdr != NULL); fsz = _libelf_fsize(ELF_T_EHDR, ec, e->e_version, (size_t) 1); - msz = _libelf_msize(ELF_T_EHDR, ec, e->e_version); + if ((msz = _libelf_msize(ELF_T_EHDR, ec, e->e_version)) == 0) + return ((off_t) -1); em = _libelf_elfmachine(e); @@ -885,15 +894,17 @@ _libelf_write_phdr(Elf *e, unsigned char Elf32_Ehdr *eh32; Elf64_Ehdr *eh64; Elf_Data dst, src; - size_t fsz, phnum; + size_t fsz, msz, phnum; uint64_t phoff; assert(ex->ex_type == ELF_EXTENT_PHDR); ec = e->e_class; + ehdr = _libelf_ehdr(e, ec, 0); - phnum = e->e_u.e_elf.e_nphdr; + assert(ehdr != NULL); + phnum = e->e_u.e_elf.e_nphdr; assert(phnum > 0); if (ec == ELFCLASS32) { @@ -913,14 +924,15 @@ _libelf_write_phdr(Elf *e, unsigned char (void) memset(&dst, 0, sizeof(dst)); (void) memset(&src, 0, sizeof(src)); + if ((msz = _libelf_msize(ELF_T_PHDR, ec, e->e_version)) == 0) + return ((off_t) -1); fsz = _libelf_fsize(ELF_T_PHDR, ec, e->e_version, phnum); assert(fsz > 0); src.d_buf = _libelf_getphdr(e, ec); src.d_version = dst.d_version = e->e_version; src.d_type = ELF_T_PHDR; - src.d_size = phnum * _libelf_msize(ELF_T_PHDR, ec, - e->e_version); + src.d_size = phnum * msz; dst.d_size = fsz; dst.d_buf = nf + ex->ex_start; @@ -945,13 +957,16 @@ _libelf_write_shdr(Elf *e, unsigned char uint64_t shoff; Elf32_Ehdr *eh32; Elf64_Ehdr *eh64; - size_t fsz, nscn; + size_t fsz, msz, nscn; Elf_Data dst, src; assert(ex->ex_type == ELF_EXTENT_SHDR); ec = e->e_class; + ehdr = _libelf_ehdr(e, ec, 0); + assert(ehdr != NULL); + nscn = e->e_u.e_elf.e_nscn; if (ec == ELFCLASS32) { @@ -971,8 +986,11 @@ _libelf_write_shdr(Elf *e, unsigned char (void) memset(&dst, 0, sizeof(dst)); (void) memset(&src, 0, sizeof(src)); + if ((msz = _libelf_msize(ELF_T_SHDR, ec, e->e_version)) == 0) + return ((off_t) -1); + src.d_type = ELF_T_SHDR; - src.d_size = _libelf_msize(ELF_T_SHDR, ec, e->e_version); + src.d_size = msz; src.d_version = dst.d_version = e->e_version; fsz = _libelf_fsize(ELF_T_SHDR, ec, e->e_version, (size_t) 1); @@ -1109,12 +1127,14 @@ _libelf_write_elf(Elf *e, off_t newsize, assert((e->e_flags & LIBELF_F_RAWFILE_MALLOC) || (e->e_flags & LIBELF_F_RAWFILE_MMAP)); if (e->e_flags & LIBELF_F_RAWFILE_MALLOC) { + assert((e->e_flags & LIBELF_F_RAWFILE_MMAP) == 0); free(e->e_rawfile); e->e_rawfile = newfile; newfile = NULL; } #if ELFTC_HAVE_MMAP else if (e->e_flags & LIBELF_F_RAWFILE_MMAP) { + assert((e->e_flags & LIBELF_F_RAWFILE_MALLOC) == 0); if ((e->e_rawfile = mmap(NULL, (size_t) newsize, PROT_READ, MAP_PRIVATE, e->e_fd, (off_t) 0)) == MAP_FAILED) { Index: gelf.3 =================================================================== RCS file: /cvs/src/lib/libelf/gelf.3,v retrieving revision 1.2 diff -u -p -r1.2 gelf.3 --- gelf.3 11 Jun 2019 18:30:31 -0000 1.2 +++ gelf.3 11 May 2020 06:10:12 -0000 @@ -23,11 +23,11 @@ .\" .\" $Id: gelf.3,v 1.2 2019/06/11 18:30:31 schwarze Exp $ .\" -.Dd September 1, 2006 +.Dd June 12, 2019 .Dt GELF 3 .Os .Sh NAME -.Nm GElf +.Nm gelf .Nd class-independent API for ELF manipulation .Sh LIBRARY .Lb libelf Index: gelf_cap.c =================================================================== RCS file: /cvs/src/lib/libelf/gelf_cap.c,v retrieving revision 1.1 diff -u -p -r1.1 gelf_cap.c --- gelf_cap.c 1 Feb 2019 05:27:37 -0000 1.1 +++ gelf_cap.c 11 May 2020 06:10:12 -0000 @@ -67,9 +67,8 @@ gelf_getcap(Elf_Data *ed, int ndx, GElf_ return (NULL); } - msz = _libelf_msize(ELF_T_CAP, ec, e->e_version); - - assert(msz > 0); + if ((msz = _libelf_msize(ELF_T_CAP, ec, e->e_version)) == 0) + return (NULL); if (msz * (size_t) ndx >= d->d_data.d_size) { LIBELF_SET_ERROR(ARGUMENT, 0); @@ -127,8 +126,8 @@ gelf_update_cap(Elf_Data *ed, int ndx, G return (0); } - msz = _libelf_msize(ELF_T_CAP, ec, e->e_version); - assert(msz > 0); + if ((msz = _libelf_msize(ELF_T_CAP, ec, e->e_version)) == 0) + return (0); if (msz * (size_t) ndx >= d->d_data.d_size) { LIBELF_SET_ERROR(ARGUMENT, 0); Index: gelf_dyn.c =================================================================== RCS file: /cvs/src/lib/libelf/gelf_dyn.c,v retrieving revision 1.1 diff -u -p -r1.1 gelf_dyn.c --- gelf_dyn.c 1 Feb 2019 05:27:37 -0000 1.1 +++ gelf_dyn.c 11 May 2020 06:10:12 -0000 @@ -67,9 +67,9 @@ gelf_getdyn(Elf_Data *ed, int ndx, GElf_ return (NULL); } - msz = _libelf_msize(ELF_T_DYN, ec, e->e_version); + if ((msz = _libelf_msize(ELF_T_DYN, ec, e->e_version)) == 0) + return (NULL); - assert(msz > 0); assert(ndx >= 0); if (msz * (size_t) ndx >= d->d_data.d_size) { @@ -127,9 +127,9 @@ gelf_update_dyn(Elf_Data *ed, int ndx, G return (0); } - msz = _libelf_msize(ELF_T_DYN, ec, e->e_version); + if ((msz = _libelf_msize(ELF_T_DYN, ec, e->e_version)) == 0) + return (0); - assert(msz > 0); assert(ndx >= 0); if (msz * (size_t) ndx >= d->d_data.d_size) { Index: gelf_getcap.3 =================================================================== RCS file: /cvs/src/lib/libelf/gelf_getcap.3,v retrieving revision 1.1 diff -u -p -r1.1 gelf_getcap.3 --- gelf_getcap.3 1 Feb 2019 05:27:37 -0000 1.1 +++ gelf_getcap.3 11 May 2020 06:10:12 -0000 @@ -23,7 +23,7 @@ .\" .\" $Id: gelf_getcap.3,v 1.1 2019/02/01 05:27:37 jsg Exp $ .\" -.Dd August 29, 2006 +.Dd April 22, 2019 .Dt GELF_GETCAP 3 .Os .Sh NAME @@ -113,6 +113,12 @@ was not associated with a section of typ .Dv SHT_SUNW_cap . .It Bq Er ELF_E_RANGE A value was not representable in the target type. +.It Bq Er ELF_E_VERSION +The +.Vt Elf_Data +descriptor denoted by argument +.Ar data +is associated with an ELF object with an unsupported version. .El .Sh SEE ALSO .Xr elf 3 , Index: gelf_getdyn.3 =================================================================== RCS file: /cvs/src/lib/libelf/gelf_getdyn.3,v retrieving revision 1.1 diff -u -p -r1.1 gelf_getdyn.3 --- gelf_getdyn.3 1 Feb 2019 05:27:37 -0000 1.1 +++ gelf_getdyn.3 11 May 2020 06:10:12 -0000 @@ -23,7 +23,7 @@ .\" .\" $Id: gelf_getdyn.3,v 1.1 2019/02/01 05:27:37 jsg Exp $ .\" -.Dd August 29, 2006 +.Dd April 22, 2019 .Dt GELF_GETDYN 3 .Os .Sh NAME @@ -115,6 +115,13 @@ was not associated with a section of typ .Dv SHT_DYNAMIC . .It Bq Er ELF_E_RANGE A value was not representable in the target type. +.It Bq Er ELF_E_VERSION +The +.Vt Elf_Data +descriptor denoted by argument +.Ar data +is associated with an ELF object with an unsupported version. +.El .El .Sh SEE ALSO .Xr elf 3 , Index: gelf_getmove.3 =================================================================== RCS file: /cvs/src/lib/libelf/gelf_getmove.3,v retrieving revision 1.1 diff -u -p -r1.1 gelf_getmove.3 --- gelf_getmove.3 1 Feb 2019 05:27:37 -0000 1.1 +++ gelf_getmove.3 11 May 2020 06:10:12 -0000 @@ -23,7 +23,7 @@ .\" .\" $Id: gelf_getmove.3,v 1.1 2019/02/01 05:27:37 jsg Exp $ .\" -.Dd August 29, 2006 +.Dd April 22, 2019 .Dt GELF_GETMOVE 3 .Os .Sh NAME @@ -112,6 +112,12 @@ Data descriptor was not associated with a section containing move information. .It Bq Er ELF_E_RANGE A value was not representable in the target type. +.It Bq Er ELF_E_VERSION +The +.Vt Elf_Data +descriptor denoted by argument +.Ar data +is associated with an ELF object with an unsupported version. .El .Sh SEE ALSO .Xr elf 3 , Index: gelf_getrel.3 =================================================================== RCS file: /cvs/src/lib/libelf/gelf_getrel.3,v retrieving revision 1.1 diff -u -p -r1.1 gelf_getrel.3 --- gelf_getrel.3 1 Feb 2019 05:27:38 -0000 1.1 +++ gelf_getrel.3 11 May 2020 06:10:12 -0000 @@ -23,7 +23,7 @@ .\" .\" $Id: gelf_getrel.3,v 1.1 2019/02/01 05:27:38 jsg Exp $ .\" -.Dd August 29, 2006 +.Dd April 22, 2019 .Dt GELF_GETREL 3 .Os .Sh NAME @@ -113,6 +113,12 @@ was not associated with a section of typ .Dv SHT_REL . .It Bq Er ELF_E_RANGE A value was not representable in the target type. +.It Bq Er ELF_E_VERSION +The +.Vt Elf_Data +descriptor denoted by argument +.Ar data +is associated with an ELF object with an unsupported version. .El .Sh SEE ALSO .Xr elf 3 , Index: gelf_getrela.3 =================================================================== RCS file: /cvs/src/lib/libelf/gelf_getrela.3,v retrieving revision 1.1 diff -u -p -r1.1 gelf_getrela.3 --- gelf_getrela.3 1 Feb 2019 05:27:38 -0000 1.1 +++ gelf_getrela.3 11 May 2020 06:10:12 -0000 @@ -23,7 +23,7 @@ .\" .\" $Id: gelf_getrela.3,v 1.1 2019/02/01 05:27:38 jsg Exp $ .\" -.Dd August 29, 2006 +.Dd April 22, 2019 .Dt GELF_GETRELA 3 .Os .Sh NAME @@ -113,6 +113,12 @@ was not associated with a section of typ .Dv SHT_RELA . .It Bq Er ELF_E_RANGE A value was not representable in the target type. +.It Bq Er ELF_E_VERSION +The +.Vt Elf_Data +descriptor denoted by argument +.Ar data +is associated with an ELF object with an unsupported version. .El .Sh SEE ALSO .Xr elf 3 , Index: gelf_getsym.3 =================================================================== RCS file: /cvs/src/lib/libelf/gelf_getsym.3,v retrieving revision 1.1 diff -u -p -r1.1 gelf_getsym.3 --- gelf_getsym.3 1 Feb 2019 05:27:38 -0000 1.1 +++ gelf_getsym.3 11 May 2020 06:10:12 -0000 @@ -23,7 +23,7 @@ .\" .\" $Id: gelf_getsym.3,v 1.1 2019/02/01 05:27:38 jsg Exp $ .\" -.Dd August 29, 2006 +.Dd April 22, 2019 .Dt GELF_GETSYM 3 .Os .Sh NAME @@ -115,6 +115,12 @@ Data descriptor was not associated with a section containing symbol information. .It Bq Er ELF_E_RANGE A value was not representable in the target type. +.It Bq Er ELF_E_VERSION +The +.Vt Elf_Data +descriptor denoted by argument +.Ar data +is associated with an ELF object with an unsupported version. .El .Sh SEE ALSO .Xr elf 3 , Index: gelf_getsyminfo.3 =================================================================== RCS file: /cvs/src/lib/libelf/gelf_getsyminfo.3,v retrieving revision 1.1 diff -u -p -r1.1 gelf_getsyminfo.3 --- gelf_getsyminfo.3 1 Feb 2019 05:27:38 -0000 1.1 +++ gelf_getsyminfo.3 11 May 2020 06:10:12 -0000 @@ -23,7 +23,7 @@ .\" .\" $Id: gelf_getsyminfo.3,v 1.1 2019/02/01 05:27:38 jsg Exp $ .\" -.Dd August 29, 2006 +.Dd April 22, 2019 .Dt GELF_GETSYMINFO 3 .Os .Sh NAME @@ -105,6 +105,12 @@ descriptor. Data descriptor .Ar data was not associated with a section containing symbol information. +.It Bq Er ELF_E_VERSION +The +.Vt Elf_Data +descriptor denoted by argument +.Ar data +is associated with an ELF object with an unsupported version. .El .Sh SEE ALSO .Xr elf 3 , Index: gelf_getsymshndx.3 =================================================================== RCS file: /cvs/src/lib/libelf/gelf_getsymshndx.3,v retrieving revision 1.1 diff -u -p -r1.1 gelf_getsymshndx.3 --- gelf_getsymshndx.3 1 Feb 2019 05:27:38 -0000 1.1 +++ gelf_getsymshndx.3 11 May 2020 06:10:12 -0000 @@ -23,7 +23,7 @@ .\" .\" $Id: gelf_getsymshndx.3,v 1.1 2019/02/01 05:27:38 jsg Exp $ .\" -.Dd November 5, 2006 +.Dd April 22, 2019 .Dt GELF_GETSYMSHNDX 3 .Os .Sh NAME @@ -152,6 +152,14 @@ Data descriptor and .Ar xndxdata were associated with different ELF objects. +.It Bq Er ELF_E_VERSION +The +.Vt Elf_Data +descriptors denoted by arguments +.Ar symdata +and +.Ar xndxdata +are associated with an ELF object with an unsupported version. .El .Sh SEE ALSO .Xr elf 3 , Index: gelf_move.c =================================================================== RCS file: /cvs/src/lib/libelf/gelf_move.c,v retrieving revision 1.1 diff -u -p -r1.1 gelf_move.c --- gelf_move.c 1 Feb 2019 05:27:38 -0000 1.1 +++ gelf_move.c 11 May 2020 06:10:12 -0000 @@ -67,9 +67,9 @@ gelf_getmove(Elf_Data *ed, int ndx, GElf return (NULL); } - msz = _libelf_msize(ELF_T_MOVE, ec, e->e_version); + if ((msz = _libelf_msize(ELF_T_MOVE, ec, e->e_version)) == 0) + return (NULL); - assert(msz > 0); assert(ndx >= 0); if (msz * (size_t) ndx >= d->d_data.d_size) { @@ -130,9 +130,9 @@ gelf_update_move(Elf_Data *ed, int ndx, return (0); } - msz = _libelf_msize(ELF_T_MOVE, ec, e->e_version); + if ((msz = _libelf_msize(ELF_T_MOVE, ec, e->e_version)) == 0) + return (0); - assert(msz > 0); assert(ndx >= 0); if (msz * (size_t) ndx >= d->d_data.d_size) { Index: gelf_newehdr.3 =================================================================== RCS file: /cvs/src/lib/libelf/gelf_newehdr.3,v retrieving revision 1.2 diff -u -p -r1.2 gelf_newehdr.3 --- gelf_newehdr.3 11 Jun 2019 18:30:31 -0000 1.2 +++ gelf_newehdr.3 11 May 2020 06:10:12 -0000 @@ -23,7 +23,7 @@ .\" .\" $Id: gelf_newehdr.3,v 1.2 2019/06/11 18:30:31 schwarze Exp $ .\" -.Dd October 22, 2007 +.Dd June 12, 2019 .Dt GELF_NEWEHDR 3 .Os .Sh NAME Index: gelf_newphdr.3 =================================================================== RCS file: /cvs/src/lib/libelf/gelf_newphdr.3,v retrieving revision 1.2 diff -u -p -r1.2 gelf_newphdr.3 --- gelf_newphdr.3 11 Jun 2019 18:30:31 -0000 1.2 +++ gelf_newphdr.3 11 May 2020 06:10:12 -0000 @@ -23,7 +23,7 @@ .\" .\" $Id: gelf_newphdr.3,v 1.2 2019/06/11 18:30:31 schwarze Exp $ .\" -.Dd October 22, 2007 +.Dd June 12, 2019 .Dt GELF_NEWPHDR 3 .Os .Sh NAME Index: gelf_rel.c =================================================================== RCS file: /cvs/src/lib/libelf/gelf_rel.c,v retrieving revision 1.1 diff -u -p -r1.1 gelf_rel.c --- gelf_rel.c 1 Feb 2019 05:27:38 -0000 1.1 +++ gelf_rel.c 11 May 2020 06:10:12 -0000 @@ -67,9 +67,9 @@ gelf_getrel(Elf_Data *ed, int ndx, GElf_ return (NULL); } - msz = _libelf_msize(ELF_T_REL, ec, e->e_version); + if ((msz = _libelf_msize(ELF_T_REL, ec, e->e_version)) == 0) + return (NULL); - assert(msz > 0); assert(ndx >= 0); if (msz * (size_t) ndx >= d->d_data.d_size) { @@ -129,9 +129,9 @@ gelf_update_rel(Elf_Data *ed, int ndx, G return (0); } - msz = _libelf_msize(ELF_T_REL, ec, e->e_version); + if ((msz = _libelf_msize(ELF_T_REL, ec, e->e_version)) == 0) + return (0); - assert(msz > 0); assert(ndx >= 0); if (msz * (size_t) ndx >= d->d_data.d_size) { @@ -144,7 +144,7 @@ gelf_update_rel(Elf_Data *ed, int ndx, G LIBELF_COPY_U32(rel32, dr, r_offset); - if (ELF64_R_SYM(dr->r_info) > ELF32_R_SYM(~0UL) || + if (ELF64_R_SYM(dr->r_info) > ELF32_R_SYM(~0U) || ELF64_R_TYPE(dr->r_info) > ELF32_R_TYPE(~0U)) { LIBELF_SET_ERROR(RANGE, 0); return (0); Index: gelf_rela.c =================================================================== RCS file: /cvs/src/lib/libelf/gelf_rela.c,v retrieving revision 1.1 diff -u -p -r1.1 gelf_rela.c --- gelf_rela.c 1 Feb 2019 05:27:38 -0000 1.1 +++ gelf_rela.c 11 May 2020 06:10:12 -0000 @@ -67,9 +67,9 @@ gelf_getrela(Elf_Data *ed, int ndx, GElf return (NULL); } - msz = _libelf_msize(ELF_T_RELA, ec, e->e_version); + if ((msz = _libelf_msize(ELF_T_RELA, ec, e->e_version)) == 0) + return (NULL); - assert(msz > 0); assert(ndx >= 0); if (msz * (size_t) ndx >= d->d_data.d_size) { @@ -130,9 +130,9 @@ gelf_update_rela(Elf_Data *ed, int ndx, return (0); } - msz = _libelf_msize(ELF_T_RELA, ec, e->e_version); + if ((msz = _libelf_msize(ELF_T_RELA, ec, e->e_version)) == 0) + return (0); - assert(msz > 0); assert(ndx >= 0); if (msz * (size_t) ndx >= d->d_data.d_size) { @@ -145,7 +145,7 @@ gelf_update_rela(Elf_Data *ed, int ndx, LIBELF_COPY_U32(rela32, dr, r_offset); - if (ELF64_R_SYM(dr->r_info) > ELF32_R_SYM(~0UL) || + if (ELF64_R_SYM(dr->r_info) > ELF32_R_SYM(~0U) || ELF64_R_TYPE(dr->r_info) > ELF32_R_TYPE(~0U)) { LIBELF_SET_ERROR(RANGE, 0); return (0); Index: gelf_sym.c =================================================================== RCS file: /cvs/src/lib/libelf/gelf_sym.c,v retrieving revision 1.1 diff -u -p -r1.1 gelf_sym.c --- gelf_sym.c 1 Feb 2019 05:27:38 -0000 1.1 +++ gelf_sym.c 11 May 2020 06:10:12 -0000 @@ -67,9 +67,9 @@ gelf_getsym(Elf_Data *ed, int ndx, GElf_ return (NULL); } - msz = _libelf_msize(ELF_T_SYM, ec, e->e_version); + if ((msz = _libelf_msize(ELF_T_SYM, ec, e->e_version)) == 0) + return (NULL); - assert(msz > 0); assert(ndx >= 0); if (msz * (size_t) ndx >= d->d_data.d_size) { @@ -129,9 +129,9 @@ gelf_update_sym(Elf_Data *ed, int ndx, G return (0); } - msz = _libelf_msize(ELF_T_SYM, ec, e->e_version); + if ((msz = _libelf_msize(ELF_T_SYM, ec, e->e_version)) == 0) + return (0); - assert(msz > 0); assert(ndx >= 0); if (msz * (size_t) ndx >= d->d_data.d_size) { Index: gelf_syminfo.c =================================================================== RCS file: /cvs/src/lib/libelf/gelf_syminfo.c,v retrieving revision 1.1 diff -u -p -r1.1 gelf_syminfo.c --- gelf_syminfo.c 1 Feb 2019 05:27:38 -0000 1.1 +++ gelf_syminfo.c 11 May 2020 06:10:12 -0000 @@ -65,9 +65,9 @@ gelf_getsyminfo(Elf_Data *ed, int ndx, G return (NULL); } - msz = _libelf_msize(ELF_T_SYMINFO, ec, e->e_version); + if ((msz = _libelf_msize(ELF_T_SYMINFO, ec, e->e_version)) == 0) + return (NULL); - assert(msz > 0); assert(ndx >= 0); if (msz * (size_t) ndx >= d->d_data.d_size) { @@ -126,9 +126,9 @@ gelf_update_syminfo(Elf_Data *ed, int nd return (0); } - msz = _libelf_msize(ELF_T_SYMINFO, ec, e->e_version); + if ((msz = _libelf_msize(ELF_T_SYMINFO, ec, e->e_version)) == 0) + return (0); - assert(msz > 0); assert(ndx >= 0); if (msz * (size_t) ndx >= d->d_data.d_size) { Index: gelf_symshndx.c =================================================================== RCS file: /cvs/src/lib/libelf/gelf_symshndx.c,v retrieving revision 1.1 diff -u -p -r1.1 gelf_symshndx.c --- gelf_symshndx.c 1 Feb 2019 05:27:38 -0000 1.1 +++ gelf_symshndx.c 11 May 2020 06:10:12 -0000 @@ -69,9 +69,9 @@ gelf_getsymshndx(Elf_Data *d, Elf_Data * return (NULL); } - msz = _libelf_msize(ELF_T_WORD, ec, e->e_version); + if ((msz = _libelf_msize(ELF_T_WORD, ec, e->e_version)) == 0) + return (NULL); - assert(msz > 0); assert(ndx >= 0); if (msz * (size_t) ndx >= id->d_size) { @@ -121,9 +121,9 @@ gelf_update_symshndx(Elf_Data *d, Elf_Da return (0); } - msz = _libelf_msize(ELF_T_WORD, ec, e->e_version); + if ((msz = _libelf_msize(ELF_T_WORD, ec, e->e_version)) == 0) + return (0); - assert(msz > 0); assert(ndx >= 0); if (msz * (size_t) ndx >= id->d_size) { Index: libelf_allocate.c =================================================================== RCS file: /cvs/src/lib/libelf/libelf_allocate.c,v retrieving revision 1.2 diff -u -p -r1.2 libelf_allocate.c --- libelf_allocate.c 19 Mar 2019 02:31:35 -0000 1.2 +++ libelf_allocate.c 11 May 2020 06:10:12 -0000 @@ -76,7 +76,7 @@ _libelf_init_elf(Elf *e, Elf_Kind kind) } } -Elf * +void _libelf_release_elf(Elf *e) { Elf_Arhdr *arh; @@ -114,8 +114,6 @@ _libelf_release_elf(Elf *e) } free(e); - - return (NULL); } struct _Libelf_Data * Index: libelf_convert.m4 =================================================================== RCS file: /cvs/src/lib/libelf/libelf_convert.m4,v retrieving revision 1.2 diff -u -p -r1.2 libelf_convert.m4 --- libelf_convert.m4 19 Mar 2019 02:31:35 -0000 1.2 +++ libelf_convert.m4 11 May 2020 06:10:12 -0000 @@ -971,6 +971,7 @@ _libelf_cvt_NOTE_tom(unsigned char *dst, if (count < sz || dsz < sz) /* Buffers are too small. */ return (0); + /* Copy the remainder of the note as-is. */ (void) memcpy(dst, src, sz); src += sz; @@ -1025,6 +1026,7 @@ _libelf_cvt_NOTE_tof(unsigned char *dst, if (count < sz) sz = count; + /* Copy the remainder of the note as-is. */ (void) memcpy(dst, src, sz); src += sz; Index: libelf_data.c =================================================================== RCS file: /cvs/src/lib/libelf/libelf_data.c,v retrieving revision 1.1 diff -u -p -r1.1 libelf_data.c --- libelf_data.c 1 Feb 2019 05:27:38 -0000 1.1 +++ libelf_data.c 11 May 2020 06:10:12 -0000 @@ -89,8 +89,14 @@ _libelf_xlate_shtype(uint32_t sht) * OS, processor and user-defined section types) are * legal, but since we do not know anything more about * their semantics, we return a type of ELF_T_BYTE. + * + * The ELF specification uses 32 bit unsigned values for + * denoting section types, and defines SHT_HIUSER to be + * 0xFFFFFFFFUL (i.e., UINT32_MAX). Consequently, we only + * need to check that 'sht' is greater than or equal to + * SHT_LOOS. */ - if (sht >= SHT_LOOS && sht <= SHT_HIUSER) + if (sht >= SHT_LOOS) return (ELF_T_BYTE); /* Index: libelf_ehdr.c =================================================================== RCS file: /cvs/src/lib/libelf/libelf_ehdr.c,v retrieving revision 1.2 diff -u -p -r1.2 libelf_ehdr.c --- libelf_ehdr.c 19 Mar 2019 02:31:35 -0000 1.2 +++ libelf_ehdr.c 11 May 2020 06:10:12 -0000 @@ -148,9 +148,8 @@ _libelf_ehdr(Elf *e, int ec, int allocat return (NULL); } - msz = _libelf_msize(ELF_T_EHDR, ec, EV_CURRENT); - - assert(msz > 0); + if ((msz = _libelf_msize(ELF_T_EHDR, ec, EV_CURRENT)) == 0) + return (NULL); if ((ehdr = calloc((size_t) 1, msz)) == NULL) { LIBELF_SET_ERROR(RESOURCE, 0); Index: libelf_memory.c =================================================================== RCS file: /cvs/src/lib/libelf/libelf_memory.c,v retrieving revision 1.2 diff -u -p -r1.2 libelf_memory.c --- libelf_memory.c 19 Mar 2019 02:31:35 -0000 1.2 +++ libelf_memory.c 11 May 2020 06:10:12 -0000 @@ -78,7 +78,7 @@ _libelf_memory(unsigned char *image, siz if (error != ELF_E_NONE) { if (reporterror) { LIBELF_PRIVATE(error) = LIBELF_ERROR(error, 0); - (void) _libelf_release_elf(e); + _libelf_release_elf(e); return (NULL); } } else { Index: libelf_msize.m4 =================================================================== RCS file: /cvs/src/lib/libelf/libelf_msize.m4,v retrieving revision 1.1 diff -u -p -r1.1 libelf_msize.m4 --- libelf_msize.m4 1 Feb 2019 05:27:38 -0000 1.1 +++ libelf_msize.m4 11 May 2020 06:10:12 -0000 @@ -87,6 +87,14 @@ static struct msize msize[ELF_T_NUM] = { MSIZES(ELF_TYPE_LIST) }; +/* + * Returns the memory size of the specified ELF type 't' of ELF + * class 'ec' and ELF version 'version'. + * + * If the specified combination of ELF type, class, and version is + * unsupported then a value of 0 will be returned and the appropriate + * library error code set. + */ size_t _libelf_msize(Elf_Type t, int elfclass, unsigned int version) { @@ -101,6 +109,11 @@ _libelf_msize(Elf_Type t, int elfclass, } sz = (elfclass == ELFCLASS32) ? msize[t].msz32 : msize[t].msz64; + + if (sz == 0) { + LIBELF_SET_ERROR(UNIMPL, 0); + return (0); + } return (sz); } Index: libelf_phdr.c =================================================================== RCS file: /cvs/src/lib/libelf/libelf_phdr.c,v retrieving revision 1.2 diff -u -p -r1.2 libelf_phdr.c --- libelf_phdr.c 19 Mar 2019 02:31:35 -0000 1.2 +++ libelf_phdr.c 11 May 2020 06:10:12 -0000 @@ -87,9 +87,8 @@ _libelf_getphdr(Elf *e, int ec) return (NULL); } - msz = _libelf_msize(ELF_T_PHDR, ec, EV_CURRENT); - - assert(msz > 0); + if ((msz = _libelf_msize(ELF_T_PHDR, ec, EV_CURRENT)) == 0) + return (NULL); if ((phdr = calloc(phnum, msz)) == NULL) { LIBELF_SET_ERROR(RESOURCE, 0); @@ -130,9 +129,8 @@ _libelf_newphdr(Elf *e, int ec, size_t c assert(ec == ELFCLASS32 || ec == ELFCLASS64); assert(e->e_version == EV_CURRENT); - msz = _libelf_msize(ELF_T_PHDR, ec, e->e_version); - - assert(msz > 0); + if ((msz = _libelf_msize(ELF_T_PHDR, ec, e->e_version)) == 0) + return (NULL); newphdr = NULL; if (count > 0 && (newphdr = calloc(count, msz)) == NULL) { Index: libelf_xlate.c =================================================================== RCS file: /cvs/src/lib/libelf/libelf_xlate.c,v retrieving revision 1.1 diff -u -p -r1.1 libelf_xlate.c --- libelf_xlate.c 1 Feb 2019 05:27:38 -0000 1.1 +++ libelf_xlate.c 11 May 2020 06:10:12 -0000 @@ -84,9 +84,8 @@ _libelf_xlate(Elf_Data *dst, const Elf_D (src->d_type, (size_t) 1, src->d_version)) == 0) return (NULL); - msz = _libelf_msize(src->d_type, elfclass, src->d_version); - - assert(msz > 0); + if ((msz = _libelf_msize(src->d_type, elfclass, src->d_version)) == 0) + return (NULL); if (src->d_size % (direction == ELF_TOMEMORY ? fsz : msz)) { LIBELF_SET_ERROR(DATA, 0);