0008-Use-sh_offset-instead-of-sh_addr-when-checking-alrea.patch 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. From cb8326de54ad7a56658b0dc8efb7da5e71684a7c Mon Sep 17 00:00:00 2001
  2. From: Pablo Galindo <pablogsal@gmail.com>
  3. Date: Tue, 22 Sep 2020 01:33:47 +0100
  4. Subject: [PATCH] Use sh_offset instead of sh_addr when checking already
  5. replaced libs
  6. When checking for already replaced libs, the check against the size must
  7. be done using the section header offset, not the section file address.
  8. This was not crashing in many situations because normally sh_address and
  9. sh_offset have the same value but these two may differ and using the
  10. sh_address value instead can cause library corruption in these
  11. situations.
  12. Fetch from: https://github.com/NixOS/patchelf/commit/83aa89addf8757e2d63aa73222f2fa9bc6d7321a
  13. Backported to v0.9
  14. Signed-off-by: Conrad Ratschan <conrad.ratschan@rockwellcollins.com>
  15. ---
  16. src/patchelf.cc | 2 +-
  17. 1 file changed, 1 insertion(+), 1 deletion(-)
  18. diff --git a/src/patchelf.cc b/src/patchelf.cc
  19. index 4676157..c025ae2 100644
  20. --- a/src/patchelf.cc
  21. +++ b/src/patchelf.cc
  22. @@ -666,7 +666,7 @@ void ElfFile<ElfFileParamNames>::rewriteSectionsLibrary()
  23. /* Some sections may already be replaced so account for that */
  24. unsigned int i = 1;
  25. Elf_Addr pht_size = sizeof(Elf_Ehdr) + (phdrs.size() + 1)*sizeof(Elf_Phdr);
  26. - while( shdrs[i].sh_addr <= pht_size && i < rdi(hdr->e_shnum) ) {
  27. + while( shdrs[i].sh_offset <= pht_size && i < rdi(hdr->e_shnum) ) {
  28. if (not haveReplacedSection(getSectionName(shdrs[i])))
  29. replaceSection(getSectionName(shdrs[i]), shdrs[i].sh_size);
  30. i++;
  31. --
  32. 2.17.1