You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.6 KiB

  1. From cfc45e911e21820bc8b703b37e947a6a7e5d798a Mon Sep 17 00:00:00 2001
  2. From: David Lamparter <equinox@opensourcerouting.org>
  3. Date: Tue, 18 Jan 2022 09:50:25 +0100
  4. Subject: [PATCH] lib/clippy: don't endian-convert twice
  5. elf_getdata_rawchunk() already endian-converts; doing it again is, uh,
  6. counterproductive.
  7. Fixes: #10051
  8. Reported-by: Lucian Cristian <lucian.cristian@gmail.com>
  9. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
  10. ---
  11. lib/elf_py.c | 29 ++++++++++++++---------------
  12. 1 file changed, 14 insertions(+), 15 deletions(-)
  13. --- a/lib/elf_py.c
  14. +++ b/lib/elf_py.c
  15. @@ -1071,26 +1071,25 @@ static void elffile_add_dynreloc(struct
  16. * always be a pointer...
  17. */
  18. if (elffile_virt2file(w, rel->r_offset, &offs)) {
  19. - Elf_Data *ptr, *conv;
  20. - GElf_Addr tmp;
  21. - Elf_Data mem = {
  22. - .d_buf = (void *)&tmp,
  23. - .d_type = ELF_T_ADDR,
  24. - .d_version = EV_CURRENT,
  25. - .d_size = sizeof(tmp),
  26. - .d_off = 0,
  27. - .d_align = 0,
  28. - };
  29. + Elf_Data *ptr;
  30. + /* NB: this endian-converts! */
  31. ptr = elf_getdata_rawchunk(w->elf, offs,
  32. w->elfclass / 8,
  33. ELF_T_ADDR);
  34. - conv = gelf_xlatetom(w->elf, &mem, ptr,
  35. - w->mmap[EI_DATA]);
  36. - if (conv) {
  37. - memcpy(&rel_offs, conv->d_buf,
  38. - conv->d_size);
  39. + if (ptr) {
  40. + char *dst = (char *)&rel_offs;
  41. +
  42. + /* sigh. it endian-converts. but
  43. + * doesn't size-convert.
  44. + */
  45. + if (BYTE_ORDER == BIG_ENDIAN &&
  46. + ptr->d_size < sizeof(rel_offs))
  47. + dst += sizeof(rel_offs) -
  48. + ptr->d_size;
  49. +
  50. + memcpy(dst, ptr->d_buf, ptr->d_size);
  51. relw->relative = false;
  52. relw->rela->r_addend = rel_offs;