* [RFA] Fix Ada memory corruption
@ 2009-11-19 19:01 Keith Seitz
2009-11-19 19:21 ` Joel Brobecker
0 siblings, 1 reply; 3+ messages in thread
From: Keith Seitz @ 2009-11-19 19:01 UTC (permalink / raw)
To: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 395 bytes --]
Hi,
Tom's recent symbol_set_names patch exposed this Ada bug, which results
in memory corruption while computing an alternate symbol name.
This fixes the crash I was seeing in gdb.ada/interface.exp tests.
Ok?
Keith
ChangeLog
2009-11-19 Keith Seitz <keiths@redhat.com>
* ada-lang.c (find_old_style_renaming_symbol): Change
function_name to const and use strncpy to stript the
suffix.
[-- Attachment #2: ada-mem-err.patch --]
[-- Type: text/plain, Size: 2037 bytes --]
Index: ada-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/ada-lang.c,v
retrieving revision 1.229
diff -u -p -r1.229 ada-lang.c
--- ada-lang.c 2 Jul 2009 17:25:52 -0000 1.229
+++ ada-lang.c 19 Nov 2009 18:51:42 -0000
@@ -6505,7 +6505,7 @@ find_old_style_renaming_symbol (const ch
qualified. This means we need to prepend the function name
as well as adding the ``___XR'' suffix to build the name of
the associated renaming symbol. */
- char *function_name = SYMBOL_LINKAGE_NAME (function_sym);
+ const char *function_name = SYMBOL_LINKAGE_NAME (function_sym);
/* Function names sometimes contain suffixes used
for instance to qualify nested subprograms. When building
the XR type name, we need to make sure that this suffix is
@@ -6514,9 +6514,11 @@ find_old_style_renaming_symbol (const ch
const int function_name_len = ada_name_prefix_len (function_name);
const int rename_len = function_name_len + 2 /* "__" */
+ strlen (name) + 6 /* "___XR\0" */ ;
+ int bufsize = rename_len * sizeof (char);
/* Strip the suffix if necessary. */
- function_name[function_name_len] = '\0';
+ int end = (strlen (function_name) > function_name_len
+ ? function_name_len : strlen (function_name));
/* Library-level functions are a special case, as GNAT adds
a ``_ada_'' prefix to the function name to avoid namespace
@@ -6526,9 +6528,10 @@ find_old_style_renaming_symbol (const ch
&& strstr (function_name, "_ada_") == function_name)
function_name = function_name + 5;
- rename = (char *) alloca (rename_len * sizeof (char));
- xsnprintf (rename, rename_len * sizeof (char), "%s__%s___XR",
- function_name, name);
+ rename = (char *) alloca (bufsize);
+ gdb_assert (end < bufsize);
+ strncpy (rename, function_name, end);
+ xsnprintf (rename, bufsize - end, "__%s___XR", name);
}
else
{
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [RFA] Fix Ada memory corruption
2009-11-19 19:01 [RFA] Fix Ada memory corruption Keith Seitz
@ 2009-11-19 19:21 ` Joel Brobecker
2009-11-19 22:50 ` Joel Brobecker
0 siblings, 1 reply; 3+ messages in thread
From: Joel Brobecker @ 2009-11-19 19:21 UTC (permalink / raw)
To: Keith Seitz; +Cc: gdb-patches
> ChangeLog
> 2009-11-19 Keith Seitz <keiths@redhat.com>
>
> * ada-lang.c (find_old_style_renaming_symbol): Change
> function_name to const and use strncpy to stript the
> suffix.
Gah! I was just working on this yesterday evening. I haven't finished,
but while I'm at it, I'm merging it with some local changes. I'll see
if I can apply your change on top of mine, and then commit.
Thanks for the patch!
--
Joel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [RFA] Fix Ada memory corruption
2009-11-19 19:21 ` Joel Brobecker
@ 2009-11-19 22:50 ` Joel Brobecker
0 siblings, 0 replies; 3+ messages in thread
From: Joel Brobecker @ 2009-11-19 22:50 UTC (permalink / raw)
To: Keith Seitz; +Cc: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 560 bytes --]
> > * ada-lang.c (find_old_style_renaming_symbol): Change
> > function_name to const and use strncpy to stript the
> > suffix.
I think there was a mistake in the last part of the patch and you would
have ended up overwriting the function name with the __<var-name>___XR
portion.
I was almost done with my own version of the change, so I finished it,
tested it, and checked it in.
While working on this, I also added handling for various suffixes
that get introduced for nested/static procedures as well as special
routines (Protected Objects).
--
Joel
[-- Attachment #2: 0001-Fix-memory-corruption-during-old-style-renamings-pro.patch --]
[-- Type: text/x-diff, Size: 2842 bytes --]
gdb/
* ada-lang.c (ada_remove_Xbn_suffix): New function.
(find_old_style_renaming_symbol): Add handling for function suffixes
present in the name of various procedures.
Do not overwrite the function symbol's name.
---
gdb/ada-lang.c | 36 +++++++++++++++++++++++++++++++-----
1 files changed, 31 insertions(+), 5 deletions(-)
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index b5590f7..3c9ab77 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -873,6 +873,26 @@ ada_remove_po_subprogram_suffix (const char *encoded, int *len)
*len = *len - 1;
}
+/* Remove trailing X[bn]* suffixes (indicating names in package bodies). */
+
+static void
+ada_remove_Xbn_suffix (const char *encoded, int *len)
+{
+ int i = *len - 1;
+
+ while (i > 0 && (encoded[i] == 'b' || encoded[i] == 'n'))
+ i--;
+
+ if (encoded[i] != 'X')
+ return;
+
+ if (i == 0)
+ return;
+
+ if (isalnum (encoded[i-1]))
+ *len = i;
+}
+
/* If ENCODED follows the GNAT entity encoding conventions, then return
the decoded form of ENCODED. Otherwise, return "<%s>" where "%s" is
replaced by ENCODED.
@@ -6514,12 +6534,14 @@ find_old_style_renaming_symbol (const char *name, struct block *block)
the XR type name, we need to make sure that this suffix is
not included. So do not include any suffix in the function
name length below. */
- const int function_name_len = ada_name_prefix_len (function_name);
+ int function_name_len = ada_name_prefix_len (function_name);
const int rename_len = function_name_len + 2 /* "__" */
+ strlen (name) + 6 /* "___XR\0" */ ;
/* Strip the suffix if necessary. */
- function_name[function_name_len] = '\0';
+ ada_remove_trailing_digits (function_name, &function_name_len);
+ ada_remove_po_subprogram_suffix (function_name, &function_name_len);
+ ada_remove_Xbn_suffix (function_name, &function_name_len);
/* Library-level functions are a special case, as GNAT adds
a ``_ada_'' prefix to the function name to avoid namespace
@@ -6527,11 +6549,15 @@ find_old_style_renaming_symbol (const char *name, struct block *block)
have this prefix, so we need to skip this prefix if present. */
if (function_name_len > 5 /* "_ada_" */
&& strstr (function_name, "_ada_") == function_name)
- function_name = function_name + 5;
+ {
+ function_name += 5;
+ function_name_len -= 5;
+ }
rename = (char *) alloca (rename_len * sizeof (char));
- xsnprintf (rename, rename_len * sizeof (char), "%s__%s___XR",
- function_name, name);
+ strncpy (rename, function_name, function_name_len);
+ xsnprintf (rename + function_name_len, rename_len - function_name_len,
+ "__%s___XR", name);
}
else
{
--
1.6.0.4
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2009-11-19 22:50 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-11-19 19:01 [RFA] Fix Ada memory corruption Keith Seitz
2009-11-19 19:21 ` Joel Brobecker
2009-11-19 22:50 ` Joel Brobecker
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox