aboutsummaryrefslogtreecommitdiff
path: root/bfd
diff options
context:
space:
mode:
authorNick Clifton <nickc@redhat.com>2023-08-04 14:19:28 +0100
committerNick Clifton <nickc@redhat.com>2023-08-04 14:19:28 +0100
commit0133072f87b7ac0791413870876a0769ca7d44e0 (patch)
tree8716a44e4d9a42e75365227277d69301756cc6c9 /bfd
parentbabce214ecb2a093606186a3f82d579cb026a925 (diff)
downloadgdb-0133072f87b7ac0791413870876a0769ca7d44e0.zip
gdb-0133072f87b7ac0791413870876a0769ca7d44e0.tar.gz
gdb-0133072f87b7ac0791413870876a0769ca7d44e0.tar.bz2
Fix potential infinite loop in bfd_cache_close_all.
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.
Diffstat (limited to 'bfd')
-rw-r--r--bfd/ChangeLog7
-rw-r--r--bfd/cache.c15
2 files changed, 20 insertions, 2 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 0087aed..1404220 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,10 @@
+2023-08-04 Nick Clifton <nickc@redhat.com>
+
+ 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 <tromey@adacore.com>
* pei-x86_64.c (PEI_HEADERS): Do not define.
diff --git a/bfd/cache.c b/bfd/cache.c
index 0c6a948..357a38d 100644
--- a/bfd/cache.c
+++ b/bfd/cache.c
@@ -546,7 +546,9 @@ SYNOPSIS
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.
<<FALSE>> is returned if closing one of the file fails, <<TRUE>> is
returned if all is well.
@@ -558,7 +560,16 @@ bfd_cache_close_all (void)
bool ret = true;
while (bfd_last_cache != NULL)
- ret &= bfd_cache_close (bfd_last_cache);
+ {
+ bfd *prev_bfd_last_cache = bfd_last_cache;
+
+ ret &= bfd_cache_close (bfd_last_cache);
+
+ /* Stop a potential infinite loop should bfd_cache_close()
+ not update bfd_last_cache. */
+ if (bfd_last_cache == prev_bfd_last_cache)
+ break;
+ }
return ret;
}