| From 408b67531424f88242b4b5d40e11a5cb7af6e895 Mon Sep 17 00:00:00 2001 |
| From: Alan Modra <amodra@gmail.com> |
| Date: Sat, 13 Aug 2022 15:32:47 +0930 |
| Subject: [PATCH 1/3] PR29482 - strip: heap-buffer-overflow |
| |
| PR 29482 |
| * coffcode.h (coff_set_section_contents): Sanity check _LIB. |
| --- |
| bfd/coffcode.h | 7 +++++-- |
| 1 file changed, 5 insertions(+), 2 deletions(-) |
| |
| diff --git a/bfd/coffcode.h b/bfd/coffcode.h |
| index 2fd699ff1b8..09ec2d53e75 100644 |
| --- a/bfd/coffcode.h |
| +++ b/bfd/coffcode.h |
| @@ -4177,10 +4177,13 @@ coff_set_section_contents (bfd * abfd, |
| |
| rec = (bfd_byte *) location; |
| recend = rec + count; |
| - while (rec < recend) |
| + while (recend - rec >= 4) |
| { |
| + size_t len = bfd_get_32 (abfd, rec); |
| + if (len == 0 || len > (size_t) (recend - rec) / 4) |
| + break; |
| + rec += len * 4; |
| ++section->lma; |
| - rec += bfd_get_32 (abfd, rec) * 4; |
| } |
| |
| BFD_ASSERT (rec == recend); |
| -- |
| 2.40.0.rc1.284.g88254d51c5-goog |
| |