This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Off-by-one error in windows-nat.c causes abort at startup
- From: Eli Zaretskii <eliz at gnu dot org>
- To: gdb-patches at sourceware dot org
- Date: Sat, 30 Apr 2016 14:07:45 +0300
- Subject: Off-by-one error in windows-nat.c causes abort at startup
- Authentication-results: sourceware.org; auth=none
- Reply-to: Eli Zaretskii <eliz at gnu dot org>
I created a gdb.ini file in my home directory, and suddenly found that
almost all my GDB binaries stopped working. Even "gdb --version"
would crash at startup thusly:
./common/common-utils.c:141: internal-error: xsnprintf: Assertion `ret < size' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? (y or n) [answered Y; input not from terminal]
This is a bug, please report it. For instructions, see:
<http://www.gnu.org/software/gdb/bugs/>.
./common/common-utils.c:141: internal-error: xsnprintf: Assertion `ret < size' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Create a core file of GDB? (y or n) [answered Y; input not from terminal]
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
Luckily, I still had GDB 7.5, which did work. Using it, I found the
off-by-one gotcha below (".gdbinit" is one character longer than
"gdb.ini"). I guess no one tested this feature when we switched from
using snprintf to xsnprintf...
OK to commit (with a suitable ChangeLog entry, of course)?
--- gdb/windows-nat.c~ 2016-02-10 05:19:39.000000000 +0200
+++ gdb/windows-nat.c 2016-04-30 11:57:08.500000000 +0300
@@ -2711,9 +2711,9 @@ _initialize_check_for_gdb_ini (void)
if (access (oldini, 0) == 0)
{
int len = strlen (oldini);
- char *newini = (char *) alloca (len + 1);
+ char *newini = (char *) alloca (len + 2);
- xsnprintf (newini, len + 1, "%.*s.gdbinit",
+ xsnprintf (newini, len + 2, "%.*s.gdbinit",
(int) (len - (sizeof ("gdb.ini") - 1)), oldini);
warning (_("obsolete '%s' found. Rename to '%s'."), oldini, newini);
}