This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
vfprintf_maybe_filtered should check vasprintf return value
- To: gdb-patches at sourceware dot cygnus dot com
- Subject: vfprintf_maybe_filtered should check vasprintf return value
- From: Eirik Fuller <eirik at netapp dot com>
- Date: Thu, 14 Sep 2000 18:33:21 -0700
In gdb-5.0 (and, as far as I can tell, later versions of gdb), the
return value of vasprintf is not checked by vfprintf_maybe_filtered.
I've found at least one crash which can result from this; if I try
printf "%ls\n", version
on gdb's own symbol table, I get a segfault because linebuffer is
unchanged by vasprintf, on a Debian GNU/Linux system with the
vasprintf provided by glibc-2.1.3.
With the enclosed patch, I get an error message instead of a crash.
I make no claims about the optimality of the error message, but I
believe the patch is fundamentally sound. Please let me know if
the crash isn't easily repeatable (it is for me), or if any further
information is required.
Thanks,
Eirik
2000-09-14 Eirik Fuller <eirik@netapp.com>
* utils.c (vfprintf_maybe_filtered): check vasprintf return value.
--- ../gdb-5.0/gdb/utils.c- Thu Apr 20 21:10:46 2000
+++ ../gdb-5.0/gdb/utils.c Thu Sep 14 18:19:34 2000
@@ -2023,7 +2023,9 @@ vfprintf_maybe_filtered (stream, format,
char *linebuffer;
struct cleanup *old_cleanups;
- vasprintf (&linebuffer, format, args);
+ if (vasprintf (&linebuffer, format, args) < 0)
+ error ("vfprintf_maybe_filtered: vasprintf returned error %d:\n%s.",
+ errno, strerror (errno));
if (linebuffer == NULL)
{
fputs_unfiltered ("\ngdb: virtual memory exhausted.\n", gdb_stderr);