Blame SOURCES/0007-GDB-fix-completion-related-libstdc-assert.patch

8c35ac
From ce92e458506aec5bc5516a771e26b0f907ce0db4 Mon Sep 17 00:00:00 2001
8c35ac
From: Lianbo Jiang <lijiang@redhat.com>
8c35ac
Date: Wed, 26 Jan 2022 20:32:35 +0800
8c35ac
Subject: [PATCH 07/10] GDB: fix completion related libstdc++ assert
8c35ac
8c35ac
Currently crash built with some specific flags (-D_GLIBCXX_ASSERTIONS
8c35ac
and etc.) may abort and print the following error when running the gdb
8c35ac
list command or tab-completion of symbols.  For example:
8c35ac
8c35ac
  crash> l panic
8c35ac
  /usr/include/c++/11/string_view:234: ...
8c35ac
  Aborted (core dumped)
8c35ac
8c35ac
  crash> p "TAB completion"
8c35ac
  crash> p /usr/include/c++/11/string_view:234: ...
8c35ac
  Aborted (core dumped)
8c35ac
8c35ac
When the name string is null (the length of name is zero), there are
8c35ac
multiple places where array access is out of bounds in the gdb/ada-lang.c
8c35ac
(see ada_fold_name() and ada_lookup_name_info()).
8c35ac
8c35ac
The patch backports these gdb patches:
8c35ac
6a780b676637 ("Fix completion related libstdc++ assert when using -D_GLIBCXX_DEBUG")
8c35ac
2ccee230f830 ("Fix off-by-one error in ada_fold_name")
8c35ac
8c35ac
Signed-off-by: Lianbo Jiang <lijiang@redhat.com>
8c35ac
Signed-off-by: Kazuhito Hagio <k-hagio-ab@nec.com>
8c35ac
---
8c35ac
 gdb-10.2.patch | 31 +++++++++++++++++++++++++++++++
8c35ac
 1 file changed, 31 insertions(+)
8c35ac
8c35ac
diff --git a/gdb-10.2.patch b/gdb-10.2.patch
8c35ac
index 1332b6638028..f5e4c06e6f97 100644
8c35ac
--- a/gdb-10.2.patch
8c35ac
+++ b/gdb-10.2.patch
8c35ac
@@ -1591,3 +1591,34 @@
8c35ac
    max += 2;
8c35ac
    limit = cols / max;
8c35ac
    if (limit != 1 && (limit * max == cols))
8c35ac
+--- gdb-10.2/gdb/ada-lang.c.orig
8c35ac
++++ gdb-10.2/gdb/ada-lang.c
8c35ac
+@@ -997,7 +997,7 @@ ada_fold_name (gdb::string_view name)
8c35ac
+   int len = name.size ();
8c35ac
+   GROW_VECT (fold_buffer, fold_buffer_size, len + 1);
8c35ac
+ 
8c35ac
+-  if (name[0] == '\'')
8c35ac
++  if (!name.empty () && name[0] == '\'')
8c35ac
+     {
8c35ac
+       strncpy (fold_buffer, name.data () + 1, len - 2);
8c35ac
+       fold_buffer[len - 2] = '\000';
8c35ac
+@@ -1006,8 +1006,9 @@ ada_fold_name (gdb::string_view name)
8c35ac
+     {
8c35ac
+       int i;
8c35ac
+ 
8c35ac
+-      for (i = 0; i <= len; i += 1)
8c35ac
++      for (i = 0; i < len; i += 1)
8c35ac
+         fold_buffer[i] = tolower (name[i]);
8c35ac
++      fold_buffer[i] = '\0';
8c35ac
+     }
8c35ac
+ 
8c35ac
+   return fold_buffer;
8c35ac
+@@ -13596,7 +13597,7 @@ ada_lookup_name_info::ada_lookup_name_info (const lookup_name_info &lookup_name)
8c35ac
+ {
8c35ac
+   gdb::string_view user_name = lookup_name.name ();
8c35ac
+ 
8c35ac
+-  if (user_name[0] == '<')
8c35ac
++  if (!user_name.empty () && user_name[0] == '<')
8c35ac
+     {
8c35ac
+       if (user_name.back () == '>')
8c35ac
+ 	m_encoded_name
8c35ac
-- 
8c35ac
2.20.1
8c35ac