/pidgin/main: e6937e52930b: Fix some CWE-252 coverity warnings
Tomasz Wasilczyk
twasilczyk at pidgin.im
Tue May 6 13:39:00 EDT 2014
Changeset: e6937e52930b37bcea65d855b706305889dea379
Author: Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date: 2014-05-06 19:38 +0200
Branch: release-2.x.y
URL: https://hg.pidgin.im/pidgin/main/rev/e6937e52930b
Description:
Fix some CWE-252 coverity warnings
diffstat:
finch/finch.c | 6 ++++--
finch/gntprefs.c | 6 ++++--
finch/gntrequest.c | 7 +++++--
finch/libgnt/gntbox.c | 4 ++--
finch/libgnt/gntcheckbox.c | 2 +-
finch/libgnt/gntcombobox.c | 2 +-
finch/libgnt/gntentry.c | 2 +-
finch/libgnt/gnttextview.c | 2 +-
finch/libgnt/gntwm.c | 4 +++-
finch/libgnt/wms/irssi.c | 2 +-
libpurple/ft.c | 7 ++++++-
libpurple/log.c | 14 ++++++++++----
libpurple/network.c | 5 +++--
libpurple/plugins/log_reader.c | 9 ++++++---
libpurple/protocols/bonjour/bonjour_ft.c | 3 ++-
libpurple/protocols/bonjour/jabber.c | 18 ++++++++++++++----
libpurple/protocols/irc/dcc_send.c | 3 ++-
libpurple/protocols/jabber/chat.c | 3 ++-
libpurple/protocols/jabber/si.c | 3 ++-
libpurple/protocols/oscar/peer.c | 3 ++-
libpurple/protocols/oscar/userinfo.c | 3 ++-
libpurple/protocols/simple/simple.c | 10 ++++++++--
libpurple/protocols/yahoo/util.c | 17 ++++++++++++++---
libpurple/protocols/zephyr/ZOpenPort.c | 13 ++++++++-----
libpurple/proxy.c | 15 ++++++++++-----
libpurple/stun.c | 9 +++++++--
libpurple/util.c | 7 +++++--
pidgin/gtkmain.c | 6 ++++--
pidgin/gtkprefs.c | 5 ++++-
pidgin/gtksession.c | 3 ++-
pidgin/gtkthemes.c | 5 ++++-
pidgin/plugins/spellchk.c | 5 ++---
32 files changed, 142 insertions(+), 61 deletions(-)
diffs (truncated from 636 to 300 lines):
diff --git a/finch/finch.c b/finch/finch.c
--- a/finch/finch.c
+++ b/finch/finch.c
@@ -379,8 +379,10 @@ init_libpurple(int argc, char **argv)
purple_idle_set_ui_ops(finch_idle_get_ui_ops());
path = g_build_filename(purple_user_dir(), "plugins", NULL);
- if (!g_stat(path, &st))
- g_mkdir(path, S_IRUSR | S_IWUSR | S_IXUSR);
+ if (!g_stat(path, &st)) {
+ if (g_mkdir(path, S_IRUSR | S_IWUSR | S_IXUSR) != 0)
+ fprintf(stderr, "Couldn't create plugins dir\n");
+ }
purple_plugins_add_search_path(path);
g_free(path);
diff --git a/finch/gntprefs.c b/finch/gntprefs.c
--- a/finch/gntprefs.c
+++ b/finch/gntprefs.c
@@ -155,12 +155,14 @@ get_pref_field(Prefs *prefs)
switch (prefs->type)
{
case PURPLE_PREF_BOOLEAN:
- sscanf(iter->data, "%d", &idata);
+ if (sscanf(iter->data, "%d", &idata) != 1)
+ idata = FALSE;
if (purple_prefs_get_bool(prefs->pref) == idata)
select = TRUE;
break;
case PURPLE_PREF_INT:
- sscanf(iter->data, "%d", &idata);
+ if (sscanf(iter->data, "%d", &idata) != 1)
+ idata = 0;
if (purple_prefs_get_int(prefs->pref) == idata)
select = TRUE;
break;
diff --git a/finch/gntrequest.c b/finch/gntrequest.c
--- a/finch/gntrequest.c
+++ b/finch/gntrequest.c
@@ -854,8 +854,11 @@ void finch_request_save_in_prefs(gpointe
case PURPLE_PREF_INT:
{
long int tmp = GPOINTER_TO_INT(val);
- if (type == PURPLE_REQUEST_FIELD_LIST) /* Lists always return string */
- sscanf(val, "%ld", &tmp);
+ if (type == PURPLE_REQUEST_FIELD_LIST) {
+ /* Lists always return string */
+ if (sscanf(val, "%ld", &tmp) != 1)
+ tmp = 0;
+ }
purple_prefs_set_int(id, (gint)tmp);
break;
}
diff --git a/finch/libgnt/gntbox.c b/finch/libgnt/gntbox.c
--- a/finch/libgnt/gntbox.c
+++ b/finch/libgnt/gntbox.c
@@ -232,8 +232,8 @@ gnt_box_size_request(GntWidget *widget)
h = maxh;
}
- gnt_widget_confirm_size(wid, w, h);
- gnt_widget_set_size(wid, w, h);
+ if (gnt_widget_confirm_size(wid, w, h))
+ gnt_widget_set_size(wid, w, h);
}
reposition_children(widget);
diff --git a/finch/libgnt/gntcheckbox.c b/finch/libgnt/gntcheckbox.c
--- a/finch/libgnt/gntcheckbox.c
+++ b/finch/libgnt/gntcheckbox.c
@@ -52,7 +52,7 @@ gnt_check_box_draw(GntWidget *widget)
wbkgdset(widget->window, '\0' | gnt_color_pair(GNT_COLOR_NORMAL));
mvwaddstr(widget->window, 0, 4, C_(GNT_BUTTON(cb)->priv->text));
- wmove(widget->window, 0, 1);
+ (void)wmove(widget->window, 0, 1);
GNTDEBUG;
}
diff --git a/finch/libgnt/gntcombobox.c b/finch/libgnt/gntcombobox.c
--- a/finch/libgnt/gntcombobox.c
+++ b/finch/libgnt/gntcombobox.c
@@ -96,7 +96,7 @@ gnt_combo_box_draw(GntWidget *widget)
whline(widget->window, ' ' | gnt_color_pair(type), widget->priv.width - 4 - len);
mvwaddch(widget->window, 1, widget->priv.width - 3, ACS_VLINE | gnt_color_pair(GNT_COLOR_NORMAL));
mvwaddch(widget->window, 1, widget->priv.width - 2, ACS_DARROW | gnt_color_pair(GNT_COLOR_NORMAL));
- wmove(widget->window, 1, 1);
+ (void)wmove(widget->window, 1, 1);
g_free(text);
GNTDEBUG;
diff --git a/finch/libgnt/gntentry.c b/finch/libgnt/gntentry.c
--- a/finch/libgnt/gntentry.c
+++ b/finch/libgnt/gntentry.c
@@ -299,7 +299,7 @@ gnt_entry_draw(GntWidget *widget)
curpos = gnt_util_onscreen_width(entry->scroll, entry->cursor);
if (focus)
mvwchgat(widget->window, 0, curpos, 1, A_REVERSE, GNT_COLOR_TEXT_NORMAL, NULL);
- wmove(widget->window, 0, curpos);
+ (void)wmove(widget->window, 0, curpos);
GNTDEBUG;
}
diff --git a/finch/libgnt/gnttextview.c b/finch/libgnt/gnttextview.c
--- a/finch/libgnt/gnttextview.c
+++ b/finch/libgnt/gnttextview.c
@@ -106,7 +106,7 @@ gnt_text_view_draw(GntWidget *widget)
GList *iter;
GntTextLine *line = lines->data;
- wmove(widget->window, widget->priv.height - 1 - i - comp, 0);
+ (void)wmove(widget->window, widget->priv.height - 1 - i - comp, 0);
for (iter = line->segments; iter; iter = iter->next)
{
diff --git a/finch/libgnt/gntwm.c b/finch/libgnt/gntwm.c
--- a/finch/libgnt/gntwm.c
+++ b/finch/libgnt/gntwm.c
@@ -148,7 +148,7 @@ gnt_wm_copy_win(GntWidget *widget, GntNo
int curx = active->priv.x + getcurx(active->window);
int cury = active->priv.y + getcury(active->window);
if (wmove(node->window, cury - widget->priv.y, curx - widget->priv.x) != OK)
- wmove(node->window, 0, 0);
+ (void)wmove(node->window, 0, 0);
}
}
}
@@ -1850,6 +1850,8 @@ gnt_wm_new_window_real(GntWM *wm, GntWid
maxx = getmaxx(stdscr);
maxy = getmaxy(stdscr) - 1; /* room for the taskbar */
+ maxx = MAX(0, maxx);
+ maxy = MAX(0, maxy);
x = MAX(0, x);
y = MAX(0, y);
diff --git a/finch/libgnt/wms/irssi.c b/finch/libgnt/wms/irssi.c
--- a/finch/libgnt/wms/irssi.c
+++ b/finch/libgnt/wms/irssi.c
@@ -215,7 +215,7 @@ update_conv_window_title(GntNode *node)
getyx(node->window, y, x);
wbkgdset(node->window, '\0' | COLOR_PAIR(gnt_widget_has_focus(node->me) ? GNT_COLOR_TITLE : GNT_COLOR_TITLE_D));
mvwaddstr(node->window, 0, 0, title);
- wmove(node->window, y, x);
+ (void)wmove(node->window, y, x);
if (!gnt_is_refugee()) {
update_panels();
doupdate();
diff --git a/libpurple/ft.c b/libpurple/ft.c
--- a/libpurple/ft.c
+++ b/libpurple/ft.c
@@ -1307,7 +1307,12 @@ begin_transfer(PurpleXfer *xfer, PurpleI
return;
}
- fseek(xfer->dest_fp, xfer->bytes_sent, SEEK_SET);
+ if (fseek(xfer->dest_fp, xfer->bytes_sent, SEEK_SET) != 0) {
+ purple_debug_error("xfer", "couldn't seek\n");
+ purple_xfer_show_file_error(xfer, purple_xfer_get_local_filename(xfer));
+ purple_xfer_cancel_local(xfer);
+ return;
+ }
}
if (xfer->fd != -1)
diff --git a/libpurple/log.c b/libpurple/log.c
--- a/libpurple/log.c
+++ b/libpurple/log.c
@@ -1837,8 +1837,12 @@ static GList *old_logger_list(PurpleLogT
g_snprintf(convostart, length, "%s", temp);
memset(&tm, 0, sizeof(tm));
- sscanf(convostart, "%*s %3s %d %d:%d:%d %d",
- month, &tm.tm_mday, &tm.tm_hour, &tm.tm_min, &tm.tm_sec, &tm.tm_year);
+ if (sscanf(convostart, "%*s %3s %d %d:%d:%d %d", month,
+ &tm.tm_mday, &tm.tm_hour, &tm.tm_min,
+ &tm.tm_sec, &tm.tm_year) != 6)
+ {
+ purple_debug_warning("log", "invalid date format\n");
+ }
/* Ugly hack, in case current locale is not English */
if (purple_strequal(month, "Jan")) {
tm.tm_mon= 0;
@@ -1943,8 +1947,10 @@ static char * old_logger_read (PurpleLog
const char *path = purple_stringref_value(data->pathref);
FILE *file = g_fopen(path, "rb");
char *read = g_malloc(data->length + 1);
- fseek(file, data->offset, SEEK_SET);
- result = fread(read, data->length, 1, file);
+ if (fseek(file, data->offset, SEEK_SET) != 0)
+ result = 0;
+ else
+ result = fread(read, data->length, 1, file);
if (result != 1)
purple_debug_error("log", "Unable to read from log file: %s\n", path);
fclose(file);
diff --git a/libpurple/network.c b/libpurple/network.c
--- a/libpurple/network.c
+++ b/libpurple/network.c
@@ -179,7 +179,7 @@ purple_network_get_local_system_ip(int f
ifc.ifc_req = (struct ifreq *)buffer;
ioctl(source, SIOCGIFCONF, &ifc);
- if (fd < 0)
+ if (fd < 0 && source >= 0)
close(source);
tmp = buffer;
@@ -489,7 +489,8 @@ purple_network_do_listen(unsigned short
flags = fcntl(listenfd, F_GETFL);
fcntl(listenfd, F_SETFL, flags | O_NONBLOCK);
#ifndef _WIN32
- fcntl(listenfd, F_SETFD, FD_CLOEXEC);
+ if (fcntl(listenfd, F_SETFD, FD_CLOEXEC) != 0)
+ purple_debug_warning("network", "couldn't set FD_CLOEXEC\n");
#endif
actual_port = purple_network_get_port_from_fd(listenfd);
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
@@ -1425,7 +1425,8 @@ static char * trillian_logger_read (Purp
read = g_malloc(data->length + 2);
file = g_fopen(data->path, "rb");
- fseek(file, data->offset, SEEK_SET);
+ if (fseek(file, data->offset, SEEK_SET) != 0)
+ g_return_val_if_reached(g_strdup(""));
data->length = fread(read, 1, data->length, file);
fclose(file);
@@ -1946,7 +1947,8 @@ static char *qip_logger_read(PurpleLog *
contents = g_malloc(data->length + 2);
- fseek(file, data->offset, SEEK_SET);
+ if (fseek(file, data->offset, SEEK_SET) != 0)
+ g_return_val_if_reached(g_strdup(""));
data->length = fread(contents, 1, data->length, file);
fclose(file);
@@ -2329,7 +2331,8 @@ static char *amsn_logger_read(PurpleLog
file = g_fopen(data->path, "rb");
g_return_val_if_fail(file != NULL, g_strdup(""));
- fseek(file, data->offset, SEEK_SET);
+ if (fseek(file, data->offset, SEEK_SET) != 0)
+ g_return_val_if_reached(g_strdup(""));
data->length = fread(contents, 1, data->length, file);
fclose(file);
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
@@ -815,7 +815,8 @@ bonjour_sock5_request_cb(gpointer data,
flags = fcntl(acceptfd, F_GETFL);
fcntl(acceptfd, F_SETFL, flags | O_NONBLOCK);
#ifndef _WIN32
- fcntl(acceptfd, F_SETFD, FD_CLOEXEC);
+ if (fcntl(acceptfd, F_SETFD, FD_CLOEXEC) != 0)
+ purple_debug_warning("bonjour", "couldn't set FD_CLOEXEC\n");
#endif
purple_input_remove(xfer->watcher);
diff --git a/libpurple/protocols/bonjour/jabber.c b/libpurple/protocols/bonjour/jabber.c
--- a/libpurple/protocols/bonjour/jabber.c
+++ b/libpurple/protocols/bonjour/jabber.c
@@ -656,7 +656,8 @@ static void
flags = fcntl(client_socket, F_GETFL);
fcntl(client_socket, F_SETFL, flags | O_NONBLOCK);
#ifndef _WIN32
- fcntl(client_socket, F_SETFD, FD_CLOEXEC);
+ if (fcntl(client_socket, F_SETFD, FD_CLOEXEC) != 0)
+ purple_debug_warning("bonjour", "jabber: couldn't set FD_CLOEXEC\n");
#endif
/* Look for the buddy that has opened the conversation and fill information */
@@ -775,7 +776,10 @@ bonjour_jabber_start(BonjourJabber *jdat
struct sockaddr_in6 addr6;
#ifdef IPV6_V6ONLY
int on = 1;
- setsockopt(jdata->socket6, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on));
+ if (setsockopt(jdata->socket6, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on)) != 0) {
+ purple_debug_error("bonjour", "couldn't force IPv6\n");
+ return -1;
+ }
#endif
memset(&addr6, 0, sizeof(addr6));
addr6.sin6_family = AF_INET6;
@@ -1168,8 +1172,14 @@ bonjour_jabber_close_conversation(Bonjou
/* Close the socket and remove the watcher */
if (bconv->socket >= 0) {
/* Send the end of the stream to the other end of the conversation */
- if (bconv->sent_stream_start == FULLY_SENT)
- send(bconv->socket, STREAM_END, strlen(STREAM_END), 0);
+ if (bconv->sent_stream_start == FULLY_SENT) {
+ size_t len = strlen(STREAM_END);
+ if (send(bconv->socket, STREAM_END, len, 0) != len) {
+ purple_debug_error("bonjour",
+ "bonjour_jabber_close_conversation: "
More information about the Commits
mailing list