pidgin/pidgin

Fix outstaning Coverity bugs
release-2.x.y
2014-05-15, Tomasz Wasilczyk
e2ef692ff10a
Parents 9a2250c4e9d1
Children c986b1e3fa1d
Fix outstaning Coverity bugs
--- a/libpurple/protocols/mxit/filexfer.c Mon May 12 23:55:54 2014 +0200
+++ b/libpurple/protocols/mxit/filexfer.c Thu May 15 15:01:47 2014 +0200
@@ -167,13 +167,12 @@
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 );
--- a/libpurple/protocols/sametime/sametime.c Mon May 12 23:55:54 2014 +0200
+++ b/libpurple/protocols/sametime/sametime.c Thu May 15 15:01:47 2014 +0200
@@ -2213,7 +2213,7 @@
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;
--- a/libpurple/protocols/simple/simple.c Mon May 12 23:55:54 2014 +0200
+++ b/libpurple/protocols/simple/simple.c Thu May 15 15:01:47 2014 +0200
@@ -1724,6 +1724,8 @@
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);
--- a/libpurple/protocols/zephyr/Zinternal.c Mon May 12 23:55:54 2014 +0200
+++ b/libpurple/protocols/zephyr/Zinternal.c Thu May 15 15:01:47 2014 +0200
@@ -526,13 +526,13 @@
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 @@
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;
--- a/libpurple/proxy.c Mon May 12 23:55:54 2014 +0200
+++ b/libpurple/proxy.c Thu May 15 15:01:47 2014 +0200
@@ -1720,6 +1720,11 @@
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++;
--- a/libpurple/util.c Mon May 12 23:55:54 2014 +0200
+++ b/libpurple/util.c Thu May 15 15:01:47 2014 +0200
@@ -4352,6 +4352,10 @@
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 @@
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;
}