[glib] Ensure g_key_file_load_from_file() strips a \r on a 4 KB boundary



commit 440e6f4a61e27ee95994cd6a57c9d977a4376755
Author: Benjamin Gilbert <bgilbert backtick net>
Date:   Thu Jan 27 02:04:00 2011 -0500

    Ensure g_key_file_load_from_file() strips a \r on a 4 KB boundary
    
    When g_key_file_parse_data() encountered \n, it was checking the previous
    character in the current input buffer for a \r to erase, rather than the
    previous character in the parse buffer.  If g_key_file_load_from_file()
    was given a file with a \r\n sequence straddling a 4 KB boundary, the \n
    would be the first character in the input buffer, so the \r would not be
    properly stripped.
    
    Bug #640695.
    
    Found-by: Jan Harkes <jaharkes cs cmu edu>

 glib/gkeyfile.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
---
diff --git a/glib/gkeyfile.c b/glib/gkeyfile.c
index 1f2a856..24033e7 100644
--- a/glib/gkeyfile.c
+++ b/glib/gkeyfile.c
@@ -953,7 +953,9 @@ g_key_file_parse_data (GKeyFile     *key_file,
     {
       if (data[i] == '\n')
         {
-	  if (i > 0 && data[i - 1] == '\r')
+	  if (key_file->parse_buffer->len > 0
+	      && (key_file->parse_buffer->str[key_file->parse_buffer->len - 1]
+		  == '\r'))
 	    g_string_erase (key_file->parse_buffer,
 			    key_file->parse_buffer->len - 1,
 			    1);



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