/soc/2013/ankitkv/gobjectification: 8826f95514fd: Merged default...

Ankit Vani a at nevitus.org
Thu May 15 00:46:52 EDT 2014


Changeset: 8826f95514fdba180150a7c4993a44a427b4654e
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2014-05-15 10:16 +0530
Branch:	 soc.2013.gobjectification.plugins
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/8826f95514fd

Description:

Merged default branch

diffstat:

 configure.ac                              |   23 +++--
 doc/reference/libpurple/Makefile.am       |    5 +-
 finch/libgnt/gnttextview.c                |    4 +
 libpurple/dnssrv.c                        |    8 +
 libpurple/internal.h                      |   30 ++++++-
 libpurple/log.c                           |   28 +++---
 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/roster.c       |    9 +-
 libpurple/protocols/jabber/si.c           |    9 +-
 libpurple/protocols/oscar/peer.c          |    8 +-
 libpurple/protocols/silc/util.c           |  129 ++++++-----------------------
 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                          |   27 +++++-
 libpurple/xmlnode.c                       |    4 +-
 pidgin/gtkprefs.c                         |    5 +-
 pidgin/gtkutils.c                         |    9 ++
 pidgin/plugins/spellchk.c                 |    2 +-
 po/POTFILES.in                            |    1 +
 28 files changed, 220 insertions(+), 254 deletions(-)

diffs (truncated from 1065 to 300 lines):

diff --git a/configure.ac b/configure.ac
--- a/configure.ac
+++ b/configure.ac
@@ -270,18 +270,21 @@ if test "x$is_win32" != "xyes" ; then
 fi
 AC_CHECK_LIB(resolv, __res_query)
 AC_CHECK_LIB(nsl, gethostent)
-if test "x$is_win32" != "xyes" ; then
+if test "x$is_win32" = "xyes" ; then
+	AC_DEFINE(HAVE_GETADDRINFO, 1, [Define to 1 if you have the getaddrinfo function.])
+	AC_DEFINE(HAVE_INET_NTOP, 1, [Define to 1 if you have the `inet_ntop' function.])
+else
 	AC_CHECK_FUNC(socket, , [AC_CHECK_LIB(socket, socket, ,
 		[AC_MSG_ERROR([socket not found])])])
+	dnl If all goes well, by this point the previous two checks will have
+	dnl pulled in -lsocket and -lnsl if we need them.
+	AC_CHECK_FUNC(getaddrinfo,
+		[AC_DEFINE([HAVE_GETADDRINFO], [1],
+			[Define to 1 if you have the getaddrinfo function.])],
+		[AC_CHECK_LIB(socket, getaddrinfo,
+			[AC_DEFINE([HAVE_GETADDRINFO]) LIBS="-lsocket -lnsl $LIBS"], , -lnsl)])
+	AC_CHECK_FUNCS(inet_ntop)
 fi
-dnl If all goes well, by this point the previous two checks will have
-dnl pulled in -lsocket and -lnsl if we need them.
-AC_CHECK_FUNC(getaddrinfo,
-	[AC_DEFINE([HAVE_GETADDRINFO], [1],
-		[Define to 1 if you have the getaddrinfo function.])],
-	[AC_CHECK_LIB(socket, getaddrinfo,
-		[AC_DEFINE([HAVE_GETADDRINFO]) LIBS="-lsocket -lnsl $LIBS"], , -lnsl)])
-AC_CHECK_FUNCS(inet_ntop)
 AC_CHECK_FUNCS(getifaddrs)
 dnl Check for socklen_t (in Unix98)
 AC_MSG_CHECKING(for socklen_t)
@@ -875,7 +878,7 @@ if test "x$enable_consoleui" = "xyes"; t
 	    [enable_consoleui=no], [$GNT_LIBS])
 
 	if test "x$is_win32" = "xyes" ; then
-		ncurses_sys_prefix="/usr/$host/sys-root/$host"
+		ncurses_sys_prefix="/usr/$host/sys-root/mingw"
 	else
 		ncurses_sys_prefix="/usr"
 	fi
diff --git a/doc/reference/libpurple/Makefile.am b/doc/reference/libpurple/Makefile.am
--- a/doc/reference/libpurple/Makefile.am
+++ b/doc/reference/libpurple/Makefile.am
@@ -58,8 +58,9 @@ CFILE_GLOB=$(top_srcdir)/$(DOC_MODULE)/*
 # e.g. EXTRA_HFILES=$(top_srcdir}/contrib/extra.h
 # TODO: those files are not properly scanned when building out-of-tree
 EXTRA_HFILES = \
-	$(top_builddir)/$(DOC_MODULE)/version.h \
-	$(top_builddir)/$(DOC_MODULE)/purple.h
+	$(top_builddir)/$(DOC_MODULE)/enums.h \
+	$(top_builddir)/$(DOC_MODULE)/purple.h \
+	$(top_builddir)/$(DOC_MODULE)/version.h
 
 # Header files or dirs to ignore when scanning. Use base file/dir names
 # e.g. IGNORE_HFILES=gtkdebug.h gtkintl.h private_code
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
@@ -147,7 +147,6 @@
 	[(condition) ? 1 : -1]; static_assertion_failed_ ## message dummy; \
 	(void)dummy; }
 
-
 #ifdef __clang__
 
 #define PURPLE_BEGIN_IGNORE_CAST_ALIGN \
@@ -166,6 +165,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;
@@ -335,4 +342,25 @@ 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);
+
+/**
+ * A fstat alternative, like g_stat for stat.
+ *
+ * @param fd The file descriptor.
+ * @param st The stat buffer.
+ *
+ * @return the result just like for fstat.
+ */
+int
+_purple_fstat(int fd, GStatBuf *st);
+
 #endif /* _PURPLE_INTERNAL_H_ */
diff --git a/libpurple/log.c b/libpurple/log.c
--- a/libpurple/log.c
+++ b/libpurple/log.c
@@ -1704,7 +1704,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;
@@ -1720,13 +1720,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 (_purple_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 */
@@ -1734,7 +1742,7 @@ static GList *old_logger_list(PurpleLogT
 
 	index_fd = g_open(pathstr, 0, O_RDONLY);
 	if (index_fd != -1) {
-		if (fstat(index_fd, &st) != 0) {
+		if (_purple_fstat(index_fd, &st) != 0) {
 			close(index_fd);
 			index_fd = -1;
 		}
@@ -1744,6 +1752,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
 		{
@@ -1779,19 +1788,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
@@ -1409,12 +1409,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);
 
@@ -1831,8 +1835,7 @@ static GList *qip_logger_list(PurpleLogT



More information about the Commits mailing list