[patch, libgfortran] PR42742 [4.5 Regression] SIGSEGV at libgfortran/io/format.c:111

Jerry DeLisle jvdelisle@verizon.net
Fri Jan 15 03:45:00 GMT 2010


I am going to commit the following patch which is a safety net for applications 
doing ridiculous things with very long format strings.

1. It avoids the excessive use of memory that results from the parsed format 
node tree, probably exceeding available stack or heap.

2. Saves me time to work on more important bugs.

The patch simply turns off caching for large format strings.  The length is 
arbitrary.  I tested with 512 and decided to use 256.

I tested with valgrind and get a clean sweep.

Regression tested on x86-64.

Regards,

Jerry

Index: format.c
===================================================================
--- format.c	(revision 155930)
+++ format.c	(working copy)
@@ -1212,13 +1212,18 @@ revert (st_parameter_dt *dtp)

  /* parse_format()-- Parse a format string.  */

+#define FORMAT_CACHE_STRING_LIMIT 256
+
  void
  parse_format (st_parameter_dt *dtp)
  {
    format_data *fmt;
    bool format_cache_ok;

-  format_cache_ok = !is_internal_unit (dtp);
+  /* Don't cache for internal units and set an arbitrary limit on the size of
+     format strings we will cache.  (Avoids memory issues.)  */
+  format_cache_ok = !is_internal_unit (dtp)
+		    && (dtp->format_len < FORMAT_CACHE_STRING_LIMIT);

    /* Lookup format string to see if it has already been parsed.  */
    if (format_cache_ok)



More information about the Gcc-patches mailing list