From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2124) id 8698B3858C5F; Fri, 4 Aug 2023 13:19:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8698B3858C5F Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Nick Clifton To: bfd-cvs@sourceware.org Subject: [binutils-gdb] Fix potential infinite loop in bfd_cache_close_all. X-Act-Checkin: binutils-gdb X-Git-Author: Nick Clifton X-Git-Refname: refs/heads/master X-Git-Oldrev: babce214ecb2a093606186a3f82d579cb026a925 X-Git-Newrev: 0133072f87b7ac0791413870876a0769ca7d44e0 Message-Id: <20230804131956.8698B3858C5F@sourceware.org> Date: Fri, 4 Aug 2023 13:19:56 +0000 (GMT) X-BeenThere: binutils-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 04 Aug 2023 13:19:56 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D0133072f87b7= ac0791413870876a0769ca7d44e0 commit 0133072f87b7ac0791413870876a0769ca7d44e0 Author: Nick Clifton Date: Fri Aug 4 14:19:28 2023 +0100 Fix potential infinite loop in bfd_cache_close_all. =20 PR 15545 * cache.c (bfd_cache_close_all): Extend description to note = that all files will be closed, even those that are not cacheable. Add code = to prevent a possible infinite loop. Diff: --- bfd/ChangeLog | 7 +++++++ bfd/cache.c | 15 +++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 0087aed06a0..14042207ca5 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,10 @@ +2023-08-04 Nick Clifton + + PR 15545 + * cache.c (bfd_cache_close_all): Extend description to note that + all files will be closed, even those that are not cacheable. + Add code to prevent a possible infinite loop. + 2023-08-02 Tom Tromey =20 * pei-x86_64.c (PEI_HEADERS): Do not define. diff --git a/bfd/cache.c b/bfd/cache.c index 0c6a948b6d6..357a38da599 100644 --- a/bfd/cache.c +++ b/bfd/cache.c @@ -546,7 +546,9 @@ SYNOPSIS =20 DESCRIPTION Remove all BFDs from the cache. If the attached file is open, - then close it too. + then close it too. Note - despite its name this function will + close a BFD even if it is not marked as being cacheable, ie + even if bfd_get_cacheable() returns false. =20 <> is returned if closing one of the file fails, <> is returned if all is well. @@ -558,7 +560,16 @@ bfd_cache_close_all (void) bool ret =3D true; =20 while (bfd_last_cache !=3D NULL) - ret &=3D bfd_cache_close (bfd_last_cache); + { + bfd *prev_bfd_last_cache =3D bfd_last_cache; + + ret &=3D bfd_cache_close (bfd_last_cache); + + /* Stop a potential infinite loop should bfd_cache_close() + not update bfd_last_cache. */ + if (bfd_last_cache =3D=3D prev_bfd_last_cache) + break; + } =20 return ret; }