glib r7194 - in trunk: . glib



Author: matthiasc
Date: Wed Jul 16 21:42:48 2008
New Revision: 7194
URL: http://svn.gnome.org/viewvc/glib?rev=7194&view=rev

Log:
        * glib/gfileutils.c (get_contents_stdio): Detect overflow and
        error out. Reported by Morten Welinder.



Modified:
   trunk/ChangeLog
   trunk/glib/gfileutils.c

Modified: trunk/glib/gfileutils.c
==============================================================================
--- trunk/glib/gfileutils.c	(original)
+++ trunk/glib/gfileutils.c	Wed Jul 16 21:42:48 2008
@@ -577,13 +577,28 @@
         }
 
       memcpy (str + total_bytes, buf, bytes);
+
+      if (total_bytes + bytes < total_bytes) 
+        {
+          g_set_error (error,
+                       G_FILE_ERROR,
+                       G_FILE_ERROR_FAILED,
+                       _("File \"%s\" is too large"),
+                       display_filename);
+
+          goto error;
+        }
+
       total_bytes += bytes;
     }
 
   fclose (f);
 
   if (total_allocated == 0)
-    str = g_new (gchar, 1);
+    {
+      str = g_new (gchar, 1);
+      total_bytes = 0;
+    }
 
   str[total_bytes] = '\0';
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]