lib/clippy: don't endian-convert twice

elf_getdata_rawchunk() already endian-converts; doing it again is, uh,
counterproductive.

Fixes: #10051
Reported-by: Lucian Cristian <lucian.cristian@gmail.com>
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
This commit is contained in:
David Lamparter 2022-01-18 09:50:25 +01:00
parent 0fd57f5600
commit cfc45e911e

View File

@ -1071,26 +1071,25 @@ static void elffile_add_dynreloc(struct elffile *w, Elf_Data *reldata,
* always be a pointer... * always be a pointer...
*/ */
if (elffile_virt2file(w, rel->r_offset, &offs)) { if (elffile_virt2file(w, rel->r_offset, &offs)) {
Elf_Data *ptr, *conv; Elf_Data *ptr;
GElf_Addr tmp;
Elf_Data mem = {
.d_buf = (void *)&tmp,
.d_type = ELF_T_ADDR,
.d_version = EV_CURRENT,
.d_size = sizeof(tmp),
.d_off = 0,
.d_align = 0,
};
/* NB: this endian-converts! */
ptr = elf_getdata_rawchunk(w->elf, offs, ptr = elf_getdata_rawchunk(w->elf, offs,
w->elfclass / 8, w->elfclass / 8,
ELF_T_ADDR); ELF_T_ADDR);
conv = gelf_xlatetom(w->elf, &mem, ptr, if (ptr) {
w->mmap[EI_DATA]); char *dst = (char *)&rel_offs;
if (conv) {
memcpy(&rel_offs, conv->d_buf, /* sigh. it endian-converts. but
conv->d_size); * doesn't size-convert.
*/
if (BYTE_ORDER == BIG_ENDIAN &&
ptr->d_size < sizeof(rel_offs))
dst += sizeof(rel_offs) -
ptr->d_size;
memcpy(dst, ptr->d_buf, ptr->d_size);
relw->relative = false; relw->relative = false;
relw->rela->r_addend = rel_offs; relw->rela->r_addend = rel_offs;