/pidgin/main: e2ef692ff10a: Fix outstaning Coverity bugs

Tomasz Wasilczyk <[email protected]>
Newsgroups gmane.comp.gnome.gaim.cvs
Message-ID <[email protected]>
Changeset: e2ef692ff10a549b230c168732b50567effc1ec4
Author:	 Tomasz Wasilczyk <[email protected]>
Date:	 2014-05-15 15:01 +0200
Branch:	 release-2.x.y
URL: https://hg.pidgin.im/pidgin/main/rev/e2ef692ff10a

Description:

Fix outstaning Coverity bugs

diffstat:

 libpurple/protocols/mxit/filexfer.c     |  5 ++---
 libpurple/protocols/sametime/sametime.c |  2 +-
 libpurple/protocols/simple/simple.c     |  2 ++
 libpurple/protocols/zephyr/Zinternal.c  |  8 ++++----
 libpurple/proxy.c                       |  5 +++++
 libpurple/util.c                        |  8 ++++++++
 6 files changed, 22 insertions(+), 8 deletions(-)

diffs (118 lines):

diff --git a/libpurple/protocols/mxit/filexfer.c b/libpurple/protocols/mxit/filexfer.c
--- a/libpurple/protocols/mxit/filexfer.c
+++ b/libpurple/protocols/mxit/filexfer.c
@@ -167,13 +167,12 @@ static void mxit_xfer_start( PurpleXfer*
 		filesize = purple_xfer_get_bytes_remaining( xfer );
 		buffer = g_malloc( filesize );
 
-		if ( fread( buffer, filesize, 1, xfer->dest_fp ) > 0 ) {
+		if (fread(buffer, filesize, 1, xfer->dest_fp) == 1) {
 			/* send data */
 			wrote = purple_xfer_write( xfer, buffer, filesize );
 			if ( wrote > 0 )
 				purple_xfer_set_bytes_sent( xfer, wrote );
-		}
-		else {
+		} else {
 			/* file read error */
 			purple_xfer_error( purple_xfer_get_type( xfer ), purple_xfer_get_account( xfer ), purple_xfer_get_remote_user( xfer ), _( "Unable to access the local file" ) );
 			purple_xfer_cancel_local( xfer );
diff --git a/libpurple/protocols/sametime/sametime.c b/libpurple/protocols/sametime/sametime.c
--- a/libpurple/protocols/sametime/sametime.c
+++ b/libpurple/protocols/sametime/sametime.c
@@ -2213,7 +2213,7 @@ static void ft_send(struct mwFileTransfe
   rem = mwFileTransfer_getRemaining(ft);
   if(rem < MW_FT_LEN) o.len = rem;
 
-  if(fread(buf, (size_t) o.len, 1, fp)) {
+  if (fread(buf, (size_t)o.len, 1, fp) == 1) {
 
     /* calculate progress and display it */
     xfer->bytes_sent += o.len;
diff --git a/libpurple/protocols/simple/simple.c b/libpurple/protocols/simple/simple.c
--- a/libpurple/protocols/simple/simple.c
+++ b/libpurple/protocols/simple/simple.c
@@ -1724,6 +1724,8 @@ static void simple_newconn_cb(gpointer d
 	int newfd;
 
 	newfd = accept(source, NULL, NULL);
+	g_return_if_fail(newfd > 0);
+
 	_purple_network_set_common_socket_flags(newfd);
 
 	conn = connection_create(sip, newfd);
diff --git a/libpurple/protocols/zephyr/Zinternal.c b/libpurple/protocols/zephyr/Zinternal.c
--- a/libpurple/protocols/zephyr/Zinternal.c
+++ b/libpurple/protocols/zephyr/Zinternal.c
@@ -526,13 +526,13 @@ Code_t Z_AddNoticeToEntry(qptr, notice, 
 		hole = hole->next;
 	    }
 	    if (lasthole) {
-		if (!(lasthole->next = (struct _Z_Hole *)
+		if (!(lasthole->next = (struct _Z_Hole *)(struct _Z_InputQ *)
 		      malloc(sizeof(struct _Z_InputQ))))
 		    return (ENOMEM);
 		hole = lasthole->next;
 	    }
 	    else {
-		if (!(qptr->holelist = (struct _Z_Hole *)
+		if (!(qptr->holelist = (struct _Z_Hole *)(struct _Z_InputQ *)
 		      malloc(sizeof(struct _Z_InputQ))))
 		    return (ENOMEM);
 		hole = qptr->holelist;
@@ -550,13 +550,13 @@ Code_t Z_AddNoticeToEntry(qptr, notice, 
 		hole = hole->next;
 	    }
 	    if (lasthole) {
-		if (!(lasthole->next = (struct _Z_Hole *)
+		if (!(lasthole->next = (struct _Z_Hole *)(struct _Z_InputQ *)
 		      malloc(sizeof(struct _Z_InputQ))))
 		    return (ENOMEM);
 		hole = lasthole->next;
 	    }
 	    else {
-		if (!(qptr->holelist = (struct _Z_Hole *)
+		if (!(qptr->holelist = (struct _Z_Hole *)(struct _Z_InputQ *)
 		      malloc(sizeof(struct _Z_InputQ))))
 		    return (ENOMEM);
 		hole = qptr->holelist;
diff --git a/libpurple/proxy.c b/libpurple/proxy.c
--- a/libpurple/proxy.c
+++ b/libpurple/proxy.c
@@ -1720,6 +1720,11 @@ s5_parse_chap_msg(PurpleProxyConnectData
 	navas = *cmdbuf;
 
 	purple_debug_misc("socks5 proxy", "Expecting %d attribute(s).\n", navas);
+	if (G_UNLIKELY(navas > 10000)) { /* XXX: what's the threshold? */
+		purple_proxy_connect_data_disconnect(connect_data,
+			_("Received invalid data on connection with server"));
+		return -1;
+	}
 
 	cmdbuf++;
 
diff --git a/libpurple/util.c b/libpurple/util.c
--- a/libpurple/util.c
+++ b/libpurple/util.c
@@ -4352,6 +4352,10 @@ purple_url_encode(const char *str)
 			for (i = 0; i < bytes; i++) {
 				if (j > (BUF_LEN - 4))
 					break;
+				if (i >= sizeof(utf_char)) {
+					g_warn_if_reached();
+					break;
+				}
 				sprintf(buf + j, "%%%02X", utf_char[i] & 0xff);
 				j += 3;
 			}
@@ -5007,6 +5011,10 @@ purple_escape_filename(const char *str)
 			for (i = 0; i < bytes; i++) {
 				if (j > (BUF_LEN - 4))
 					break;
+				if (i >= sizeof(utf_char)) {
+					g_warn_if_reached();
+					break;
+				}
 				sprintf(buf + j, "%%%02x", utf_char[i] & 0xff);
 				j += 3;
 			}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.