* [patch, fortran] Fix PR 32977
@ 2007-08-03 21:57 Thomas Koenig
2007-08-03 22:03 ` FX Coudert
0 siblings, 1 reply; 3+ messages in thread
From: Thomas Koenig @ 2007-08-03 21:57 UTC (permalink / raw)
To: fortran; +Cc: gcc-patches
[-- Attachment #1: Type: text/plain, Size: 762 bytes --]
:ADDPATCH fortran:
Hello world,
looks like vsnprintf wasn't available on every platform after all.
This patch fixes that by using a buffer that should be large enough,
and by issuing an error message in case of a buffer overflow.
Because the buffer is static, chances are pretty good that an overrun
won't clobber the other automatic variables in that routine.
Regression-tested on i686-pc-linux-gnu twice:
- with the #ifdef HAVE_VSNPRINTF replaced by #if 0 to check that
codepath
- 'as is', to check the normal codepath
without any regressions.
OK for trunk?
Thomas
2007-07-29 Thomas Koenig <tkoenig@gcc.gnu.org>
PR libfortran/32977
* io/unix.c: If there is no vsnprintf, use vsprintf and issue
a fatal error when a buffer overrun occurs.
[-- Attachment #2: patch-vsprintf --]
[-- Type: text/x-patch, Size: 1350 bytes --]
Index: io/unix.c
===================================================================
--- io/unix.c (revision 127138)
+++ io/unix.c (working copy)
@@ -1386,7 +1386,8 @@ error_stream (void)
overruns, we limit the length of the buffer to ST_VPRINTF_SIZE. 2k
is big enough to completely fill a 80x25 terminal, so it shuld be
OK. We use a direct write() because it is simpler and least likely
- to be clobbered by memory corruption. */
+ to be clobbered by memory corruption. Writing an error message
+ longer than that is an error. */
#define ST_VPRINTF_SIZE 2048
@@ -1401,8 +1402,22 @@ st_vprintf (const char *format, va_list
#ifdef HAVE_VSNPRINTF
written = vsnprintf(buffer, ST_VPRINTF_SIZE, format, ap);
#else
- written = __builtin_vsnprintf(buffer, ST_VPRINTF_SIZE, format, ap);
+ written = vsprintf(buffer, format, ap);
+
+ if (written >= ST_VPRINTF_SIZE-1)
+ {
+ /* The error message was longer than our buffer. Ouch. Because
+ we may have messed up things badly, report the error and
+ quit. */
+#define ERROR_MESSAGE "Internal error: buffer overrun in st_vprintf()\n"
+ write (fd, buffer, ST_VPRINTF_SIZE-1);
+ write (fd, ERROR_MESSAGE, strlen(ERROR_MESSAGE));
+ sys_exit(2);
+#undef ERROR_MESSAGE
+
+ }
#endif
+
written = write (fd, buffer, written);
return written;
}
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [patch, fortran] Fix PR 32977
2007-08-03 21:57 [patch, fortran] Fix PR 32977 Thomas Koenig
@ 2007-08-03 22:03 ` FX Coudert
2007-08-03 22:09 ` Thomas Koenig
0 siblings, 1 reply; 3+ messages in thread
From: FX Coudert @ 2007-08-03 22:03 UTC (permalink / raw)
To: Thomas Koenig; +Cc: fortran, gcc-patches
> 2007-07-29 Thomas Koenig <tkoenig@gcc.gnu.org>
>
> PR libfortran/32977
> * io/unix.c: If there is no vsnprintf, use vsprintf and issue
> a fatal error when a buffer overrun occurs.
OK
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [patch, fortran] Fix PR 32977
2007-08-03 22:03 ` FX Coudert
@ 2007-08-03 22:09 ` Thomas Koenig
0 siblings, 0 replies; 3+ messages in thread
From: Thomas Koenig @ 2007-08-03 22:09 UTC (permalink / raw)
To: FX Coudert; +Cc: fortran, gcc-patches
On Fri, 2007-08-03 at 23:03 +0100, FX Coudert wrote:
> > 2007-07-29 Thomas Koenig <tkoenig@gcc.gnu.org>
> >
> > PR libfortran/32977
> > * io/unix.c: If there is no vsnprintf, use vsprintf and issue
> > a fatal error when a buffer overrun occurs.
>
> OK
Committed (revision 127187).
Thanks!
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2007-08-03 22:09 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-08-03 21:57 [patch, fortran] Fix PR 32977 Thomas Koenig
2007-08-03 22:03 ` FX Coudert
2007-08-03 22:09 ` Thomas Koenig
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).