comparison libpurple/protocols/myspace/myspace.c @ 17954:016f9b2d6ee0

Increase read buffer size and be more careful about overruns.
author Jeffrey Connelly <jaconnel@calpoly.edu>
date Thu, 19 Jul 2007 04:09:33 +0000
parents bde17299004b
children 9e8943111022
comparison
equal deleted inserted replaced
17953:bde17299004b 17954:016f9b2d6ee0
1096 { 1096 {
1097 guint bm; 1097 guint bm;
1098 1098
1099 bm = msim_msg_get_integer(msg, "bm"); 1099 bm = msim_msg_get_integer(msg, "bm");
1100 1100
1101 if (msim_msg_get(msg, "cv"))
1102 {
1103 purple_debug_info("msim_incoming_bm", "cv=%s",
1104 msim_msg_get_string(msg, "cv"));
1105 }
1106
1101 switch (bm) 1107 switch (bm)
1102 { 1108 {
1103 case MSIM_BM_STATUS: 1109 case MSIM_BM_STATUS:
1104 return msim_incoming_status(session, msg); 1110 return msim_incoming_status(session, msg);
1105 case MSIM_BM_INSTANT: 1111 case MSIM_BM_INSTANT:
2135 { 2141 {
2136 g_hash_table_destroy(body); 2142 g_hash_table_destroy(body);
2137 g_return_val_if_fail(uid, FALSE); 2143 g_return_val_if_fail(uid, FALSE);
2138 } 2144 }
2139 2145
2140 purple_debug_info("msim", "associating uid %d with username %s\n", uid, username); 2146 purple_debug_info("msim", "associating uid %s with username %s\n", uid, username);
2141 2147
2142 buddy = purple_find_buddy(session->account, username); 2148 buddy = purple_find_buddy(session->account, username);
2143 if (buddy) 2149 if (buddy)
2144 { 2150 {
2145 g_hash_table_foreach(body, msim_store_buddy_info_each, buddy); 2151 g_hash_table_foreach(body, msim_store_buddy_info_each, buddy);
2714 2720
2715 /* Only can handle so much data at once... 2721 /* Only can handle so much data at once...
2716 * If this happens, try recompiling with a higher MSIM_READ_BUF_SIZE. 2722 * If this happens, try recompiling with a higher MSIM_READ_BUF_SIZE.
2717 * Should be large enough to hold the largest protocol message. 2723 * Should be large enough to hold the largest protocol message.
2718 */ 2724 */
2719 if (session->rxoff == MSIM_READ_BUF_SIZE) 2725 if (session->rxoff >= MSIM_READ_BUF_SIZE)
2720 { 2726 {
2721 purple_debug_error("msim", "msim_input_cb: %d-byte read buffer full!\n", 2727 purple_debug_error("msim",
2722 MSIM_READ_BUF_SIZE); 2728 "msim_input_cb: %d-byte read buffer full! rxoff=%d\n",
2729 MSIM_READ_BUF_SIZE, session->rxoff);
2723 purple_connection_error(gc, _("Read buffer full")); 2730 purple_connection_error(gc, _("Read buffer full"));
2724 return; 2731 return;
2725 } 2732 }
2726 2733
2727 purple_debug_info("msim", "buffer at %d (max %d), reading up to %d\n", 2734 purple_debug_info("msim", "buffer at %d (max %d), reading up to %d\n",
2748 else if (n == 0) 2755 else if (n == 0)
2749 { 2756 {
2750 purple_debug_info("msim", "msim_input_cb: server disconnected\n"); 2757 purple_debug_info("msim", "msim_input_cb: server disconnected\n");
2751 purple_connection_error(gc, _("Server has disconnected")); 2758 purple_connection_error(gc, _("Server has disconnected"));
2752 return; 2759 return;
2760 }
2761
2762 if (n + session->rxoff >= MSIM_READ_BUF_SIZE)
2763 {
2764 purple_debug_info("msim_input_cb", "received %d bytes, pushing rxoff to %d, over buffer size of %d\n",
2765 n, n + session->rxoff, MSIM_READ_BUF_SIZE);
2766 purple_connection_error(gc, _("Read buffer full"));
2753 } 2767 }
2754 2768
2755 /* Null terminate */ 2769 /* Null terminate */
2756 purple_debug_info("msim", "msim_input_cb: going to null terminate " 2770 purple_debug_info("msim", "msim_input_cb: going to null terminate "
2757 "at n=%d\n", n); 2771 "at n=%d\n", n);