0013-CVE-2022-38533.patch 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. From ef186fe54aa6d281a3ff8a9528417e5cc614c797 Mon Sep 17 00:00:00 2001
  2. From: Alan Modra <amodra@gmail.com>
  3. Date: Sat, 13 Aug 2022 15:32:47 +0930
  4. Subject: [PATCH] PR29482 - strip: heap-buffer-overflow
  5. PR 29482
  6. * coffcode.h (coff_set_section_contents): Sanity check _LIB.
  7. Upstream-Status: Backport [https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=ef186fe54aa6d281a3ff8a9528417e5cc614c797]
  8. Signed-off-by: Pgowda <pgowda.cve@gmail.com>
  9. ---
  10. bfd/coffcode.h | 7 +++++--
  11. 1 file changed, 5 insertions(+), 2 deletions(-)
  12. diff --git a/bfd/coffcode.h b/bfd/coffcode.h
  13. index 67aaf158ca1..52027981c3f 100644
  14. --- a/bfd/coffcode.h
  15. +++ b/bfd/coffcode.h
  16. @@ -4302,10 +4302,13 @@ coff_set_section_contents (bfd * abfd,
  17. rec = (bfd_byte *) location;
  18. recend = rec + count;
  19. - while (rec < recend)
  20. + while (recend - rec >= 4)
  21. {
  22. + size_t len = bfd_get_32 (abfd, rec);
  23. + if (len == 0 || len > (size_t) (recend - rec) / 4)
  24. + break;
  25. + rec += len * 4;
  26. ++section->lma;
  27. - rec += bfd_get_32 (abfd, rec) * 4;
  28. }
  29. BFD_ASSERT (rec == recend);