[libsoup] Fix a content-sniffer crash with redirected URLs



commit 97391f4fed914ee3b5fd373c1881295c08df7b3f
Author: Dan Winship <danw gnome org>
Date:   Sun Jul 12 12:22:45 2009 -0400

    Fix a content-sniffer crash with redirected URLs
    
    SoupMessageHeaders was not properly cleaning up the cached
    Content-Type when a request was redirected, which meant that if the
    redirected-to URL had no Content-Type header, then
    soup_message_headers_get_content_type() would return the Content-Type
    of the original request, but
    soup_message_headers_get_one("Content-Type") would return NULL,
    causing the sniffer to crash.
    
    http://bugzilla.gnome.org/show_bug.cgi?id=588335

 libsoup/soup-message-headers.c |   20 ++++++++++++++++++--
 1 files changed, 18 insertions(+), 2 deletions(-)
---
diff --git a/libsoup/soup-message-headers.c b/libsoup/soup-message-headers.c
index 185346e..6acca0c 100644
--- a/libsoup/soup-message-headers.c
+++ b/libsoup/soup-message-headers.c
@@ -33,6 +33,7 @@
 
 typedef void (*SoupHeaderSetter) (SoupMessageHeaders *, const char *);
 static const char *intern_header_name (const char *name, SoupHeaderSetter *setter);
+static void clear_special_headers (SoupMessageHeaders *hdrs);
 
 typedef struct {
 	const char *name;
@@ -98,7 +99,6 @@ soup_message_headers_free (SoupMessageHeaders *hdrs)
 		g_array_free (hdrs->array, TRUE);
 		if (hdrs->concat)
 			g_hash_table_destroy (hdrs->concat);
-		g_free (hdrs->content_type);
 		g_slice_free (SoupMessageHeaders, hdrs);
 	}
 }
@@ -137,7 +137,7 @@ soup_message_headers_clear (SoupMessageHeaders *hdrs)
 	if (hdrs->concat)
 		g_hash_table_remove_all (hdrs->concat);
 
-	hdrs->encoding = -1;
+	clear_special_headers (hdrs);
 }
 
 /**
@@ -548,6 +548,22 @@ intern_header_name (const char *name, SoupHeaderSetter *setter)
 	return interned;
 }
 
+static void
+clear_special_headers (SoupMessageHeaders *hdrs)
+{
+	SoupHeaderSetter setter;
+	GHashTableIter iter;
+	gpointer key, value;
+
+	/* Make sure header_setters has been initialized */
+	intern_header_name ("", NULL);
+
+	g_hash_table_iter_init (&iter, header_setters);
+	while (g_hash_table_iter_next (&iter, &key, &value)) {
+		setter = value;
+		setter (hdrs, NULL);
+	}
+}
 
 /* Specific headers */
 



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