]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Fix crash in gdb_rl_callback_handler
authorTom Tromey <tromey@adacore.com>
Mon, 15 Apr 2024 18:52:05 +0000 (12:52 -0600)
committerTom Tromey <tromey@adacore.com>
Mon, 15 Apr 2024 18:52:05 +0000 (12:52 -0600)
commit bdcd50f9 ("Strip trailing newlines from input string")
introduced a crash in eof-exit.exp.  This patch fixes the problem by
adding a NULL check in the appropriate spot.

Regression tested on x86-64 Fedora 38.  I'm checking this in.

gdb/event-top.c

index f0c07ba7f64f0459d67c8b6d43f14e80ad4c97a1..6a2a75fe3dc8e1c56a8a987c8dddbffcf0e0be73 100644 (file)
@@ -254,10 +254,13 @@ gdb_rl_callback_handler (char *rl) noexcept
   /* In bracketed paste mode, pasting a complete line can result in a
      literal newline appearing at the end of LINE.  However, we never
      want this in gdb.  */
-  size_t len = strlen (rl);
-  while (len > 0 && (rl[len - 1] == '\r' || rl[len - 1] == '\n'))
-    --len;
-  rl[len] = '\0';
+  if (rl != nullptr)
+    {
+      size_t len = strlen (rl);
+      while (len > 0 && (rl[len - 1] == '\r' || rl[len - 1] == '\n'))
+       --len;
+      rl[len] = '\0';
+    }
 
   try
     {