[gtk+/gtk-3-8] gtkprintbackendfile: Fix infinite loop in _cairo_write()



commit b81117479bc0d1e0e72a835caff94ba5194e15fc
Author: Carlos Garcia Campos <cgarcia igalia com>
Date:   Wed Oct 3 19:34:09 2012 +0200

    gtkprintbackendfile: Fix infinite loop in _cairo_write()
    
    It can happen if the io channel has been closed. In that case
    g_io_channel_write_chars() returns early because of a g_return macro
    that checks if the io channel is writable. When returning from g_return
    macros, the bytes written output parameter is not updated and the error
    is not filled, so the error is not detected and the written variable is
    used uninitialized. We should check the return value of
    g_io_channel_write_chars() to break the loop.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=685419

 modules/printbackends/file/gtkprintbackendfile.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)
---
diff --git a/modules/printbackends/file/gtkprintbackendfile.c 
b/modules/printbackends/file/gtkprintbackendfile.c
index 843ce59..9fe2d78 100644
--- a/modules/printbackends/file/gtkprintbackendfile.c
+++ b/modules/printbackends/file/gtkprintbackendfile.c
@@ -291,7 +291,7 @@ _cairo_write (void                *closure,
               unsigned int         length)
 {
   GIOChannel *io = (GIOChannel *)closure;
-  gsize written;
+  gsize written = 0;
   GError *error;
 
   error = NULL;
@@ -301,14 +301,20 @@ _cairo_write (void                *closure,
 
   while (length > 0) 
     {
-      g_io_channel_write_chars (io, (const gchar *) data, length, &written, &error);
+      GIOStatus status;
 
-      if (error != NULL)
-       {
-         GTK_NOTE (PRINTING,
-                     g_print ("FILE Backend: Error writting to temp file, %s\n", error->message));
+      status = g_io_channel_write_chars (io, (const gchar *) data, length, &written, &error);
+
+      if (status == G_IO_STATUS_ERROR)
+        {
+          if (error != NULL)
+            {
+              GTK_NOTE (PRINTING,
+                        g_print ("FILE Backend: Error writting to temp file, %s\n", error->message));
+
+              g_error_free (error);
+            }
 
-          g_error_free (error);
          return CAIRO_STATUS_WRITE_ERROR;
        }    
 


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