[glib] Fix a possible crash in g_io_channel_read_chars



commit 702a96c28146f683c58281133056bf70d7b0313e
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Dec 28 00:08:56 2010 -0500

    Fix a possible crash in g_io_channel_read_chars
    
    Patch by Rui Matos, https://bugzilla.gnome.org/show_bug.cgi?id=637759

 glib/giochannel.c |   37 ++++++++++++++++++-------------------
 1 files changed, 18 insertions(+), 19 deletions(-)
---
diff --git a/glib/giochannel.c b/glib/giochannel.c
index e70e40a..8b74386 100644
--- a/glib/giochannel.c
+++ b/glib/giochannel.c
@@ -1987,39 +1987,38 @@ g_io_channel_read_to_end (GIOChannel  *channel,
  * g_io_channel_read_chars:
  * @channel: a #GIOChannel
  * @buf: a buffer to read data into
- * @count: the size of the buffer. Note that the buffer may
- *         not be complelely filled even if there is data
- *         in the buffer if the remaining data is not a
- *         complete character.
- * @bytes_read: The number of bytes read. This may be zero even on
- *              success if count < 6 and the channel's encoding is non-%NULL.
- *              This indicates that the next UTF-8 character is too wide for
- *              the buffer.
+ * @count: the size of the buffer. Note that the buffer may not be
+ *     complelely filled even if there is data in the buffer if the
+ *     remaining data is not a complete character.
+ * @bytes_read: (allow-none): The number of bytes read. This may be
+ *     zero even on success if count < 6 and the channel's encoding
+ *     is non-%NULL. This indicates that the next UTF-8 character is
+ *     too wide for the buffer.
  * @error: a location to return an error of type #GConvertError
- *         or #GIOChannelError.
+ *     or #GIOChannelError.
  *
  * Replacement for g_io_channel_read() with the new API.
  *
  * Return value: the status of the operation.
- **/
+ */
 GIOStatus
 g_io_channel_read_chars (GIOChannel  *channel,
-                         gchar	     *buf,
-                         gsize	      count,
-			 gsize       *bytes_read,
+                         gchar       *buf,
+                         gsize        count,
+                         gsize       *bytes_read,
                          GError     **error)
 {
   GIOStatus status;
   gsize got_bytes;
 
   g_return_val_if_fail (channel != NULL, G_IO_STATUS_ERROR);
-  g_return_val_if_fail ((error == NULL) || (*error == NULL),
-			G_IO_STATUS_ERROR);
+  g_return_val_if_fail ((error == NULL) || (*error == NULL), G_IO_STATUS_ERROR);
   g_return_val_if_fail (channel->is_readable, G_IO_STATUS_ERROR);
 
   if (count == 0)
     {
-      *bytes_read = 0;
+      if (bytes_read)
+        *bytes_read = 0;
       return G_IO_STATUS_NORMAL;
     }
   g_return_val_if_fail (buf != NULL, G_IO_STATUS_ERROR);
@@ -2027,13 +2026,13 @@ g_io_channel_read_chars (GIOChannel  *channel,
   if (!channel->use_buffer)
     {
       gsize tmp_bytes;
-      
+
       g_assert (!channel->read_buf || channel->read_buf->len == 0);
 
       status = channel->funcs->io_read (channel, buf, count, &tmp_bytes, error);
-      
+
       if (bytes_read)
-	*bytes_read = tmp_bytes;
+        *bytes_read = tmp_bytes;
 
       return status;
     }



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