/pidgin/main: 9eb8f52893d0: Merge release-2.x.y

Tomasz Wasilczyk twasilczyk at pidgin.im
Mon May 12 18:26:53 EDT 2014


Changeset: 9eb8f52893d08591b65058fd3760d9a22338822d
Author:	 Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date:	 2014-05-13 00:26 +0200
Branch:	 default
URL: https://hg.pidgin.im/pidgin/main/rev/9eb8f52893d0

Description:

Merge release-2.x.y

diffstat:

 finch/libgnt/gnttextview.c                |    4 +
 libpurple/dnssrv.c                        |    8 ++
 libpurple/internal.h                      |   18 +++++
 libpurple/log.c                           |   26 ++++---
 libpurple/network.c                       |   35 ++++++++--
 libpurple/plugins/log_reader.c            |   29 +++++--
 libpurple/plugins/perl/common/module.h    |   11 +++
 libpurple/protocols/bonjour/bonjour_ft.c  |   10 +--
 libpurple/protocols/bonjour/jabber.c      |    9 +--
 libpurple/protocols/irc/dcc_send.c        |    9 +--
 libpurple/protocols/jabber/jabber.c       |    2 +-
 libpurple/protocols/jabber/si.c           |    9 +--
 libpurple/protocols/oscar/peer.c          |    8 +--
 libpurple/protocols/silc/util.c           |  105 +++++++----------------------
 libpurple/protocols/simple/simple.c       |   10 +--
 libpurple/protocols/yahoo/yahoo_profile.c |    2 +-
 libpurple/protocols/zephyr/ZReadAscii.c   |    2 +-
 libpurple/protocols/zephyr/zephyr.c       |    4 +-
 libpurple/proxy.c                         |   50 +------------
 libpurple/util.c                          |    7 +-
 libpurple/xmlnode.c                       |    4 +-
 pidgin/gtkprefs.c                         |    5 +-
 pidgin/plugins/spellchk.c                 |    2 +-
 23 files changed, 161 insertions(+), 208 deletions(-)

diffs (truncated from 825 to 300 lines):

diff --git a/finch/libgnt/gnttextview.c b/finch/libgnt/gnttextview.c
--- a/finch/libgnt/gnttextview.c
+++ b/finch/libgnt/gnttextview.c
@@ -772,6 +772,10 @@ int gnt_text_view_tag_change(GntTextView
 
 				for (segs = line->segments; segs; segs = snext) {
 					GntTextSegment *seg = segs->data;
+
+					if (!line)
+						break;
+
 					snext = segs->next;
 					if (seg->start >= tag->end) {
 						/* The segment is somewhere after the tag */
diff --git a/libpurple/dnssrv.c b/libpurple/dnssrv.c
--- a/libpurple/dnssrv.c
+++ b/libpurple/dnssrv.c
@@ -555,6 +555,14 @@ resolved(gpointer data, gint source, Pur
 							responses = NULL;
 							break;
 						}
+						if (len > MAX_ADDR_RESPONSE_LEN) {
+							purple_debug_error("dnssrv", "we've read invalid number\n");
+							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);
diff --git a/libpurple/internal.h b/libpurple/internal.h
--- a/libpurple/internal.h
+++ b/libpurple/internal.h
@@ -167,6 +167,14 @@
 
 #include <glib-object.h>
 
+#ifdef __COVERITY__
+
+/* avoid TAINTED_SCALAR warning */
+#undef g_utf8_next_char
+#define g_utf8_next_char(p) (char *)((p) + 1)
+
+#endif
+
 typedef union
 {
 	struct sockaddr sa;
@@ -336,4 +344,14 @@ int *_purple_statuses_get_primitive_scor
 const gchar *
 _purple_blist_get_localized_default_group_name(void);
 
+/**
+ * Sets most commonly used socket flags: O_NONBLOCK and FD_CLOEXEC.
+ *
+ * @param fd The file descriptor for the socket.
+ *
+ * @return TRUE if succeeded, FALSE otherwise.
+ */
+gboolean
+_purple_network_set_common_socket_flags(int fd);
+
 #endif /* _PURPLE_INTERNAL_H_ */
diff --git a/libpurple/log.c b/libpurple/log.c
--- a/libpurple/log.c
+++ b/libpurple/log.c
@@ -1707,7 +1707,7 @@ static GList *old_logger_list(PurpleLogT
 	time_t log_last_modified;
 	FILE *index;
 	FILE *file;
-	int index_fd;
+	int file_fd, index_fd;
 	char *index_tmp;
 	char buf[BUF_LONG];
 	struct tm tm;
@@ -1723,13 +1723,21 @@ static GList *old_logger_list(PurpleLogT
 
 	g_free(logfile);
 
-	if (g_stat(purple_stringref_value(pathref), &st))
-	{
+	file_fd = g_open(purple_stringref_value(pathref), 0, O_RDONLY);
+	if (file_fd == -1 || (file = fdopen(file_fd, "rb")) == NULL) {
+		purple_debug_error("log",
+			"Failed to open log file \"%s\" for reading: %s\n",
+			purple_stringref_value(pathref), g_strerror(errno));
 		purple_stringref_unref(pathref);
 		g_free(pathstr);
 		return NULL;
 	}
-	else
+	if (fstat(file_fd, &st) == -1) {
+		purple_stringref_unref(pathref);
+		g_free(pathstr);
+		fclose(file);
+		return NULL;
+	} else
 		log_last_modified = st.st_mtime;
 
 	/* Change the .log extension to .idx */
@@ -1747,6 +1755,7 @@ static GList *old_logger_list(PurpleLogT
 		if (st.st_mtime < log_last_modified)
 		{
 			purple_debug_warning("log", "Index \"%s\" exists, but is older than the log.\n", pathstr);
+			close(index_fd);
 		}
 		else
 		{
@@ -1782,19 +1791,12 @@ static GList *old_logger_list(PurpleLogT
 				fclose(index);
 				purple_stringref_unref(pathref);
 
+				fclose(file);
 				return list;
 			}
 		}
 	}
 
-	if (!(file = g_fopen(purple_stringref_value(pathref), "rb"))) {
-		purple_debug_error("log", "Failed to open log file \"%s\" for reading: %s\n",
-		                   purple_stringref_value(pathref), g_strerror(errno));
-		purple_stringref_unref(pathref);
-		g_free(pathstr);
-		return NULL;
-	}
-
 	index_tmp = g_strdup_printf("%s.XXXXXX", pathstr);
 	if ((index_fd = g_mkstemp(index_tmp)) == -1) {
 		purple_debug_error("log", "Failed to open index temp file: %s\n",
diff --git a/libpurple/network.c b/libpurple/network.c
--- a/libpurple/network.c
+++ b/libpurple/network.c
@@ -403,7 +403,6 @@ purple_network_do_listen(unsigned short 
                              PurpleNetworkListenCallback cb, gpointer cb_data)
 {
 	int listenfd = -1;
-	int flags;
 	const int on = 1;
 	PurpleNetworkListenData *listen_data;
 	unsigned short actual_port;
@@ -488,12 +487,7 @@ purple_network_do_listen(unsigned short 
 		close(listenfd);
 		return NULL;
 	}
-	flags = fcntl(listenfd, F_GETFL);
-	fcntl(listenfd, F_SETFL, flags | O_NONBLOCK);
-#ifndef _WIN32
-	if (fcntl(listenfd, F_SETFD, FD_CLOEXEC) != 0)
-		purple_debug_warning("network", "couldn't set FD_CLOEXEC\n");
-#endif
+	_purple_network_set_common_socket_flags(listenfd);
 	actual_port = purple_network_get_port_from_fd(listenfd);
 
 	purple_debug_info("network", "Listening on port: %hu\n", actual_port);
@@ -1156,6 +1150,33 @@ int purple_network_convert_idn_to_ascii(
 #endif
 }
 
+gboolean
+_purple_network_set_common_socket_flags(int fd)
+{
+	int flags;
+	gboolean succ = TRUE;
+
+	g_return_val_if_fail(fd >= 0, FALSE);
+
+	flags = fcntl(fd, F_GETFL);
+
+	if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) != 0) {
+		purple_debug_warning("network",
+			"Couldn't set O_NONBLOCK flag\n");
+		succ = FALSE;
+	}
+
+#ifndef _WIN32
+	if (fcntl(fd, F_SETFD, FD_CLOEXEC) != 0) {
+		purple_debug_warning("network",
+			"Couldn't set FD_CLOEXEC flag\n");
+		succ = FALSE;
+	}
+#endif
+
+	return succ;
+}
+
 void
 purple_network_init(void)
 {
diff --git a/libpurple/plugins/log_reader.c b/libpurple/plugins/log_reader.c
--- a/libpurple/plugins/log_reader.c
+++ b/libpurple/plugins/log_reader.c
@@ -1419,12 +1419,16 @@ static char * trillian_logger_read (Purp
 
 	purple_debug_info("Trillian log read", "Reading %s\n", data->path);
 
-	read = g_malloc(data->length + 2);
-
 	file = g_fopen(data->path, "rb");
 	g_return_val_if_fail(file != NULL, g_strdup(""));
-	if (fseek(file, data->offset, SEEK_SET) != 0)
+
+	read = g_malloc(data->length + 2);
+
+	if (fseek(file, data->offset, SEEK_SET) != 0) {
+		fclose(file);
+		g_free(read);
 		g_return_val_if_reached(g_strdup(""));
+	}
 	data->length = fread(read, 1, data->length, file);
 	fclose(file);
 
@@ -1846,8 +1850,7 @@ static GList *qip_logger_list(PurpleLogT
 				} else {
 					while (*c)
 						c++;
-					if (c)
-						c--;
+					c--;
 					c = g_strrstr(c, "(");
 				}
 
@@ -1950,8 +1953,11 @@ static char *qip_logger_read(PurpleLog *
 
 	contents = g_malloc(data->length + 2);
 
-	if (fseek(file, data->offset, SEEK_SET) != 0)
+	if (fseek(file, data->offset, SEEK_SET) != 0) {
+		fclose(file);
+		g_free(contents);
 		g_return_val_if_reached(g_strdup(""));
+	}
 	data->length = fread(contents, 1, data->length, file);
 	fclose(file);
 
@@ -1994,6 +2000,8 @@ static char *qip_logger_read(PurpleLog *
 
 			/* find EOL */
 			c = strchr(c, '\n');
+			if (!c)
+				break;
 
 			/* XXX: Do we need buddy_name when we have buddy->alias? */
 			buddy_name = ++c;
@@ -2331,13 +2339,16 @@ static char *amsn_logger_read(PurpleLog 
 	g_return_val_if_fail(data->path != NULL, g_strdup(""));
 	g_return_val_if_fail(data->length > 0, g_strdup(""));
 
-	contents = g_malloc(data->length + 2);
-
 	file = g_fopen(data->path, "rb");
 	g_return_val_if_fail(file != NULL, g_strdup(""));
 
-	if (fseek(file, data->offset, SEEK_SET) != 0)
+	contents = g_malloc(data->length + 2);
+
+	if (fseek(file, data->offset, SEEK_SET) != 0) {
+		fclose(file);
+		free(contents);
 		g_return_val_if_reached(g_strdup(""));
+	}
 	data->length = fread(contents, 1, data->length, file);
 	fclose(file);
 
diff --git a/libpurple/plugins/perl/common/module.h b/libpurple/plugins/perl/common/module.h
--- a/libpurple/plugins/perl/common/module.h
+++ b/libpurple/plugins/perl/common/module.h
@@ -81,6 +81,17 @@ typedef struct group *Purple__Group;
 #include "whiteboard.h"
 #include "xmlnode.h"
 
+#ifdef __COVERITY__
+
+/* avoid extra_comma false positives */
+#undef SvPOK_only
+#define SvPOK_only(sv) { \
+	SvFLAGS(sv) &= ~(SVf_OK | SVf_IVisUV | SVf_UTF8); \
+	SvFLAGS(sv) |= (SVf_POK | SVp_POK); \
+	}
+
+#endif /* __COVERITY__ */
+
 /* account.h */
 typedef PurpleAccount *			Purple__Account;
 typedef PurpleAccountOption *		Purple__Account__Option;
diff --git a/libpurple/protocols/bonjour/bonjour_ft.c b/libpurple/protocols/bonjour/bonjour_ft.c
--- a/libpurple/protocols/bonjour/bonjour_ft.c
+++ b/libpurple/protocols/bonjour/bonjour_ft.c
@@ -810,17 +810,9 @@ bonjour_sock5_request_cb(gpointer data, 
 			purple_xfer_cancel_remote(xfer);
 			return;
 		} else {
-			int flags;
-
 			purple_debug_info("bonjour", "Accepted SOCKS5 ft connection - fd=%d\n", acceptfd);
 
-			flags = fcntl(acceptfd, F_GETFL);
-			fcntl(acceptfd, F_SETFL, flags | O_NONBLOCK);
-#ifndef _WIN32



More information about the Commits mailing list