Sat, 02 Mar 2013 17:20:56 -0500
Add some error checking for sscanf usage (there are more places that could use this)
* Also a trivial unused variable fix
--- a/finch/gntpounce.c Sat Mar 02 13:59:59 2013 -0500 +++ b/finch/gntpounce.c Sat Mar 02 17:20:56 2013 -0500 @@ -801,10 +801,8 @@ if (purple_pounce_action_is_enabled(pounce, "open-window")) { - conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, pouncee, account); - - if (conv == NULL) - conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, account, pouncee); + if (!purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, pouncee, account)) + purple_conversation_new(PURPLE_CONV_TYPE_IM, account, pouncee); } if (purple_pounce_action_is_enabled(pounce, "popup-notify"))
--- a/libpurple/example/nullclient.c Sat Mar 02 13:59:59 2013 -0500 +++ b/libpurple/example/nullclient.c Sat Mar 02 17:20:56 2013 -0500 @@ -253,7 +253,7 @@ GList *iter; int i, num; GList *names = NULL; - const char *prpl; + const char *prpl = NULL; char name[128]; char *password; GMainLoop *loop = g_main_loop_new(NULL, FALSE); @@ -289,8 +289,12 @@ fprintf(stderr, "Failed to gets protocol selection."); abort(); } - sscanf(name, "%d", &num); - prpl = g_list_nth_data(names, num); + if (sscanf(name, "%d", &num) == 1) + prpl = g_list_nth_data(names, num); + if (!prpl) { + fprintf(stderr, "Failed to gets protocol."); + abort(); + } printf("Username: "); res = fgets(name, sizeof(name), stdin);
--- a/libpurple/protocols/irc/parse.c Sat Mar 02 13:59:59 2013 -0500 +++ b/libpurple/protocols/irc/parse.c Sat Mar 02 17:20:56 2013 -0500 @@ -559,14 +559,16 @@ return buf; } else if (!strncmp(cur, "PING ", 5)) { if (notice) { /* reply */ - /* TODO: Should this read in the timestamp as a double? */ - sscanf(cur, "PING %lu", ×tamp); gc = purple_account_get_connection(irc->account); if (!gc) return NULL; - buf = g_strdup_printf(_("Reply time from %s: %lu seconds"), from, time(NULL) - timestamp); - purple_notify_info(gc, _("PONG"), _("CTCP PING reply"), buf); - g_free(buf); + /* TODO: Should this read in the timestamp as a double? */ + if (sscanf(cur, "PING %lu", ×tamp) == 1) { + buf = g_strdup_printf(_("Reply time from %s: %lu seconds"), from, time(NULL) - timestamp); + purple_notify_info(gc, _("PONG"), _("CTCP PING reply"), buf); + g_free(buf); + } else + purple_debug(PURPLE_DEBUG_ERROR, "irc", "Unable to parse PING timestamp"); return NULL; } else { buf = irc_format(irc, "vt:", "NOTICE", from, msg);
--- a/libpurple/protocols/jabber/oob.c Sat Mar 02 13:59:59 2013 -0500 +++ b/libpurple/protocols/jabber/oob.c Sat Mar 02 17:20:56 2013 -0500 @@ -138,8 +138,13 @@ lenstr = strstr(jox->headers->str, "Content-Length: "); if(lenstr) { int size; - sscanf(lenstr, "Content-Length: %d", &size); - purple_xfer_set_size(xfer, size); + if (sscanf(lenstr, "Content-Length: %d", &size) == 1) + purple_xfer_set_size(xfer, size); + else { + purple_debug_error("jabber", "Unable to parse Content-Length!\n"); + purple_xfer_cancel_local(xfer); + return 0; + } } purple_xfer_set_read_fnc(xfer, NULL);
--- a/libpurple/protocols/msn/soap.c Sat Mar 02 13:59:59 2013 -0500 +++ b/libpurple/protocols/msn/soap.c Sat Mar 02 17:20:56 2013 -0500 @@ -426,7 +426,8 @@ g_free(line); return; } else if (strcmp(key, "Content-Length") == 0) { - sscanf(value, "%" G_GSIZE_FORMAT, &(conn->body_len)); + if (sscanf(value, "%" G_GSIZE_FORMAT, &(conn->body_len)) != 1) + purple_debug_error("soap", "Unable to parse Content-Length\n"); } else if (strcmp(key, "Connection") == 0) { if (strcmp(value, "close") == 0) { conn->close_when_done = TRUE;
--- a/libpurple/util.c Sat Mar 02 13:59:59 2013 -0500 +++ b/libpurple/util.c Sat Mar 02 17:20:56 2013 -0500 @@ -3535,7 +3535,8 @@ if (f <= 1) *path = '\0'; - sscanf(port_str, "%d", &port); + if (sscanf(port_str, "%d", &port) != 1) + purple_debug_error("util", "Error parsing URL port from %s\n", url); if (ret_host != NULL) *ret_host = g_strdup(host); if (ret_port != NULL) *ret_port = port;