pidgin: 6e9635c3: Fix the code dealing with writing a TXT ...

darkrain42 at pidgin.im darkrain42 at pidgin.im
Tue Oct 13 13:32:46 EDT 2009


-----------------------------------------------------------------
Revision: 6e9635c3ba3bcf4c52a06761f5345ba29250f64f
Ancestor: 9afa0cfda64ff9907b43b21fe64f17f698d2aa0d
Author: darkrain42 at pidgin.im
Date: 2009-10-13T17:23:00
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/6e9635c3ba3bcf4c52a06761f5345ba29250f64f

Modified files:
        libpurple/dnssrv.c

ChangeLog: 

Fix the code dealing with writing a TXT lookup response from child to parent.

You can't write a pointer across a socket.

-------------- next part --------------
============================================================
--- libpurple/dnssrv.c	5cd685bde659620c50c1146fff1f7585b29cbae8
+++ libpurple/dnssrv.c	47097649babdb579e6a983f359361b0f643c7b4c
@@ -361,8 +361,12 @@ end:
 		/* TODO: Check return value */
 		if (query.type == T_SRV)
 			write(out, ret->data, sizeof(PurpleSrvResponse));
-		if (query.type == T_TXT)
-			write(out, ret->data, sizeof(PurpleTxtResponse));
+		if (query.type == T_TXT) {
+			PurpleTxtResponse *response = ret->data;
+			gsize l = strlen(response->content) + 1 /* null byte */;
+			write(out, &l, sizeof(l));
+			write(out, response->content, l);
+		}
 
 		g_free(ret->data);
 		ret = g_list_remove(ret, ret->data);
@@ -429,21 +433,38 @@ resolved(gpointer data, gint source, Pur
 					PurpleTxtCallback cb = query_data->cb.txt;
 					ssize_t red;
 					purple_debug_info("dnssrv","found %d TXT entries\n", size);
-					res = g_new0(PurpleTxtResponse, 1);
 					for (i = 0; i < size; i++) {
-						red = read(source, res, sizeof(PurpleTxtResponse));
-						if (red != sizeof(PurpleTxtResponse)) {
+						gsize len;
+
+						red = read(source, &len, sizeof(len));
+						if (red != sizeof(len)) {
 							purple_debug_error("dnssrv","unable to read txt "
+									"response length: %s\n", g_strerror(errno));
+							size = 0;
+							g_list_foreach(responses, (GFunc)purple_txt_response_destroy, NULL);
+							g_list_free(responses);
+							responses = NULL;
+							break;
+						}
+
+						res = g_new0(PurpleTxtResponse, 1);
+						res->content = g_new0(gchar, len);
+
+						red = read(source, res->content, len);
+						if (red != len) {
+							purple_debug_error("dnssrv","unable to read txt "
 									"response: %s\n", g_strerror(errno));
 							size = 0;
-							g_free(res);
+							purple_txt_response_destroy(res);
 							g_list_foreach(responses, (GFunc)purple_txt_response_destroy, NULL);
 							g_list_free(responses);
 							responses = NULL;
 							break;
 						}
+						responses = g_list_prepend(responses, res);
 					}
 
+					responses = g_list_reverse(responses);
 					cb(responses, query_data->extradata);
 				} else {
 					purple_debug_error("dnssrv", "type unknown of DNS result entry; errno is %i\n", errno);


More information about the Commits mailing list