Re: [PATCH v3 1/6] Support Mips architecture
Hi Mark, Next time I send a patch, I will add ChangeLog entry in commit message and check the added file. Thanks, Ying 在 2024/3/29 08:18, Mark Wielaard 写道: > Hi Ying, > > On Tue, Mar 05, 2024 at 05:51:17PM +0800, Ying Huang wrote: >> From: Ying Huang >> >> Signed-off-by: Ying Huang >> --- >> backends/Makefile.am| 6 +- >> backends/mips_init.c| 52 >> backends/mips_reloc.def | 93 +++ >> backends/mips_symbol.c | 63 + >> libebl/eblopenbackend.c | 2 + >> libelf/libelfP.h| 3 + >> tests/libelf.h | 541 > Note that this adds tests/libelf.h by accident. I see how that could > happen, because it should have been in .gitignore. I posted a patch > to do that: > https://inbox.sourceware.org/elfutils-devel/20240328234308.1032110-1-m...@klomp.org/ > > Besides that the patch looks fine. I did add a ChangeLog entry to the > commit message. Pushed as attached. > > Thanks, > > Mark
[PATCH] readelf: Fix division by zero in handle a relocation sections
Variable 'sh_entsize', whose possible value set allows a zero value by calling function 'gelf_fsize', is used as a denominator in calculation of 'nentries' variable. Found by RASU JSC. Signed-off-by: Maks Mishin --- src/readelf.c | 18 ++ 1 file changed, 18 insertions(+) diff --git a/src/readelf.c b/src/readelf.c index 0e931184..6701f5cf 100644 --- a/src/readelf.c +++ b/src/readelf.c @@ -2086,6 +2086,12 @@ handle_relocs_rel (Ebl *ebl, GElf_Ehdr *ehdr, Elf_Scn *scn, GElf_Shdr *shdr) { int class = gelf_getclass (ebl->elf); size_t sh_entsize = gelf_fsize (ebl->elf, ELF_T_REL, 1, EV_CURRENT); + + if (sh_entsize == 0) { + printf (_("division by zero in handle_relocs_rel() function")); + return; + } + int nentries = shdr->sh_size / sh_entsize; /* Get the data of the section. */ @@ -2275,6 +2281,12 @@ handle_relocs_rela (Ebl *ebl, GElf_Ehdr *ehdr, Elf_Scn *scn, GElf_Shdr *shdr) { int class = gelf_getclass (ebl->elf); size_t sh_entsize = gelf_fsize (ebl->elf, ELF_T_RELA, 1, EV_CURRENT); + + if (sh_entsize == 0) { + printf (_("division by zero in handle_relocs_rela() function")); + return; + } + int nentries = shdr->sh_size / sh_entsize; /* Get the data of the section. */ @@ -2469,6 +2481,12 @@ handle_relocs_relr (Ebl *ebl, Dwfl_Module *mod, Elf_Scn *scn, GElf_Shdr *shdr) { int class = gelf_getclass (ebl->elf); size_t sh_entsize = gelf_fsize (ebl->elf, ELF_T_RELR, 1, EV_CURRENT); + + if (sh_entsize == 0) { + printf (_("division by zero in handle_relocs_relr() function")); + return; + } + int nentries = shdr->sh_size / sh_entsize; /* Get the data of the section. */ -- 2.30.2
[PATCH] readelf: Fix deref-of-null in handle_core_item()
Return value of a function 'gelf_getehdr' is dereferenced without checking for NULL, but it is usually checked for this function. Found by RASU JSC. Signed-off-by: Maks Mishin --- src/readelf.c | 7 +++ 1 file changed, 7 insertions(+) diff --git a/src/readelf.c b/src/readelf.c index 0e931184..f2ec358f 100644 --- a/src/readelf.c +++ b/src/readelf.c @@ -12440,6 +12440,13 @@ handle_core_item (Elf *core, const Ebl_Core_Item *item, const void *desc, field went into the high half of USEC. */ GElf_Ehdr ehdr_mem; GElf_Ehdr *ehdr = gelf_getehdr (core, &ehdr_mem); + + if (ehdr == NULL) + { + error (0, 0, _("cannot read ELF header: %s"), elf_errmsg (-1)); + return; + } + if (likely (ehdr->e_ident[EI_DATA] == ELFDATA2MSB)) usec >>= 32; else -- 2.30.2