Fix infinite loop in is_linked_with_cygwin_dll

Message ID 20200423182225.13673-1-tromey@adacore.com
State New
Headers show
Series
  • Fix infinite loop in is_linked_with_cygwin_dll
Related show

Commit Message

Tom Tromey April 23, 2020, 6:22 p.m.
There were some Windows timeouts after the last merge.  Debugging
showed that these were caused by an infinite loop in
is_linked_with_cygwin_dll when reading C:\Windows\SysWOW64\win32u.dll.

This patch fixes the problem by ensuring that the loop always makes
progress.

gdb/ChangeLog
2020-04-23  Tom Tromey  <tromey@adacore.com>

	* windows-tdep.c (is_linked_with_cygwin_dll): Always update "iter"
	in loop.
---
 gdb/ChangeLog      |  5 +++++
 gdb/windows-tdep.c | 17 +++++++++--------
 2 files changed, 14 insertions(+), 8 deletions(-)

-- 
2.21.1

Comments

Simon Marchi April 23, 2020, 6:25 p.m. | #1
On 2020-04-23 2:22 p.m., Tom Tromey wrote:
> There were some Windows timeouts after the last merge.  Debugging

> showed that these were caused by an infinite loop in

> is_linked_with_cygwin_dll when reading C:\Windows\SysWOW64\win32u.dll.

> 

> This patch fixes the problem by ensuring that the loop always makes

> progress.


Sorry about that silly mistake.  Your patch LGTM.

Thanks,

Simon

Patch

diff --git a/gdb/windows-tdep.c b/gdb/windows-tdep.c
index e2b7960829f..153ad132b96 100644
--- a/gdb/windows-tdep.c
+++ b/gdb/windows-tdep.c
@@ -1071,18 +1071,19 @@  range [0x%" BFD_VMA_FMT "x, 0x%" BFD_VMA_FMT "x[."),
 
       const gdb_byte *name = &idata_contents[name_va - idata_section_va];
 
-      /* Make sure we don't overshoot the end of the section with the streq.  */
-      if (name + sizeof (CYGWIN_DLL_NAME) > end)
-	continue;
-
-      /* Finally, check if this is the dll name we are looking for.  */
-      if (streq ((const char *) name, CYGWIN_DLL_NAME))
-	return true;
+      /* Make sure we don't overshoot the end of the section with the
+	 streq.  */
+      if (name + sizeof (CYGWIN_DLL_NAME) <= end)
+	{
+	  /* Finally, check if this is the dll name we are looking for.  */
+	  if (streq ((const char *) name, CYGWIN_DLL_NAME))
+	    return true;
+	}
 
       iter += sizeof (pe_import_directory_entry);
     }
 
-    return false;
+  return false;
 }
 
 void _initialize_windows_tdep ();