/cpw/tomkiewicz/http: ab0560aa8ca4: Segfault shotgun debugging
Tomasz Wasilczyk
tomkiewicz at cpw.pidgin.im
Sat Oct 13 11:46:07 EDT 2012
Changeset: ab0560aa8ca4a1d48db217089eb424f72620ae2c
Author: Tomasz Wasilczyk <tomkiewicz at cpw.pidgin.im>
Date: 2012-10-13 17:45 +0200
Branch: default
URL: http://hg.pidgin.im/cpw/tomkiewicz/http/rev/ab0560aa8ca4
Description:
Segfault shotgun debugging
diffstat:
libpurple/http.c | 28 ++++++++++++++++++++++++++--
libpurple/protocols/gg/gg.c | 25 +++++++++++++++++++------
2 files changed, 45 insertions(+), 8 deletions(-)
diffs (104 lines):
diff --git a/libpurple/http.c b/libpurple/http.c
--- a/libpurple/http.c
+++ b/libpurple/http.c
@@ -327,6 +327,12 @@ static gboolean _purple_http_recv_header
{
gchar *eol, *delim;
+ if (hc->headers_got) {
+ purple_debug_error("http", "Headers already got\n");
+ _purple_http_error(hc, _("Error parsing HTTP"));
+ return FALSE;
+ }
+
g_string_append_len(hc->response_buffer, buf, len); //TODO: check max buffer length, not to raise to infinity
while ((eol = strstr(hc->response_buffer->str, "\r\n"))
!= NULL) {
@@ -467,7 +473,10 @@ static gboolean _purple_http_recv_body(P
hc->response->contents = g_string_new("");
if (hc->is_chunked)
+ {
+ hc->length_got += len;
return _purple_http_recv_body_chunked(hc, buf, len);
+ }
if (hc->length_expected >= 0 &&
len + hc->length_got > hc->length_expected)
@@ -500,8 +509,23 @@ static void _purple_http_recv(gpointer _
return;
}
- if (len == 0 && hc->headers_got)
- hc->length_expected = hc->length_got; /* TODO: error possible */
+ if (len == 0) {
+ if (hc->length_expected >= 0 &&
+ hc->length_got < hc->length_expected) {
+ purple_debug_warning("http", "No more data while reading"
+ " contents\n");
+ _purple_http_error(hc, _("Error parsing HTTP"));
+ return;
+ }
+ if (hc->headers_got)
+ hc->length_expected = hc->length_got;
+ else {
+ purple_debug_warning("http", "No more data while "
+ "parsing headers\n");
+ _purple_http_error(hc, _("Error parsing HTTP"));
+ return;
+ }
+ }
if (!hc->headers_got && len > 0) {
if (!_purple_http_recv_headers(hc, buf, len))
diff --git a/libpurple/protocols/gg/gg.c b/libpurple/protocols/gg/gg.c
--- a/libpurple/protocols/gg/gg.c
+++ b/libpurple/protocols/gg/gg.c
@@ -60,6 +60,9 @@
static void ggp_test_http_cb(PurpleHttpConnection *http_conn,
PurpleHttpResponse *response, gpointer user_data)
{
+ const gchar *data;
+ gchar *data_front, *data_tail;
+
purple_debug_info("http-test", "Testing http done %s.\n",
purple_http_response_is_successfull(response) ?
"successfully" : "without success");
@@ -67,8 +70,18 @@ static void ggp_test_http_cb(PurpleHttpC
purple_http_response_get_code(response));
purple_debug_info("http-test", "Returned error: %s.\n",
purple_http_response_get_error(response));
- purple_debug_info("http-test", "Returned content: [%s].\n",
- purple_http_response_get_data(response));
+
+ data = purple_http_response_get_data(response);
+ if (strlen(data) < 50)
+ purple_debug_info("http-test", "Returned content: [%s].\n", data);
+ else {
+ data_front = g_strndup(data, 20);
+ data_tail = g_strdup(data + strlen(data) - 20);
+ purple_debug_info("http-test", "Returned content: [%s ... %s].\n",
+ data_front, data_tail);
+ g_free(data_front);
+ g_free(data_tail);
+ }
}
static void ggp_action_test_http(PurplePluginAction *action)
@@ -76,12 +89,12 @@ static void ggp_action_test_http(PurpleP
PurpleConnection *gc = (PurpleConnection *)action->context;
purple_debug_info("http-test", "Testing http...\n");
- purple_http_get(gc, "http://www.wasilczyk.pl/x_ip_simple.htm",
- ggp_test_http_cb, NULL);
+// purple_http_get(gc, "http://www.wasilczyk.pl/x_ip_simple.htm",
+// ggp_test_http_cb, NULL);
// purple_http_get(gc, "http://google.com",
// ggp_test_http_cb, NULL);
-// purple_http_get(gc, "http://wp.pl",
-// ggp_test_http_cb, NULL);
+ purple_http_get(gc, "http://www.wp.pl",
+ ggp_test_http_cb, NULL);
purple_debug_info("http-test", "Testing http started.\n");
}
More information about the Commits
mailing list