Skip to content

Commit

Permalink
Merge pull request #10378 from FRRouting/mergify/bp/stable/8.0/pr-10360
Browse files Browse the repository at this point in the history
lib/clippy: don't endian-convert twice (backport #10360)
  • Loading branch information
donaldsharp committed Jan 20, 2022
2 parents ee92346 + 1bc75b1 commit e267ad9
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions lib/elf_py.c
Original file line number Diff line number Diff line change
Expand Up @@ -1065,26 +1065,25 @@ static void elffile_add_dynreloc(struct elffile *w, Elf_Data *reldata,
* always be a pointer...
*/
if (elffile_virt2file(w, rel->r_offset, &offs)) {
Elf_Data *ptr, *conv;
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,
};
Elf_Data *ptr;

/* NB: this endian-converts! */
ptr = elf_getdata_rawchunk(w->elf, offs,
w->elfclass / 8,
ELF_T_ADDR);

conv = gelf_xlatetom(w->elf, &mem, ptr,
w->mmap[EI_DATA]);
if (conv) {
memcpy(&rel_offs, conv->d_buf,
conv->d_size);
if (ptr) {
char *dst = (char *)&rel_offs;

/* sigh. it endian-converts. but
* 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->rela->r_addend = rel_offs;
Expand Down

0 comments on commit e267ad9

Please sign in to comment.