comparison libpurple/proxy.c @ 17452:5a51af9a61a7

fix socks5 from over-reading the headers, and throwing away data (fixes jabber file receiving)
author Nathan Walp <nwalp@pidgin.im>
date Wed, 30 May 2007 03:01:02 +0000
parents f1547260a11e
children 79ecaab86f91
comparison
equal deleted inserted replaced
17447:1a1d9cf5cd79 17452:5a51af9a61a7
1057 1057
1058 s4_canwrite(connect_data, connect_data->fd, PURPLE_INPUT_WRITE); 1058 s4_canwrite(connect_data, connect_data->fd, PURPLE_INPUT_WRITE);
1059 } 1059 }
1060 } 1060 }
1061 1061
1062 static gboolean
1063 s5_ensure_buffer_length(PurpleProxyConnectData *connect_data, int len)
1064 {
1065 if(connect_data->read_len < len) {
1066 if(connect_data->read_buf_len < len) {
1067 /* it's not just that we haven't read enough, it's that we haven't tried to read enough yet */
1068 purple_debug_info("s5", "reallocing from %d to %d\n", connect_data->read_buf_len, len);
1069 connect_data->read_buf_len = len;
1070 connect_data->read_buffer = g_realloc(connect_data->read_buffer, connect_data->read_buf_len);
1071 }
1072 return FALSE;
1073 }
1074
1075 return TRUE;
1076 }
1077
1062 static void 1078 static void
1063 s5_canread_again(gpointer data, gint source, PurpleInputCondition cond) 1079 s5_canread_again(gpointer data, gint source, PurpleInputCondition cond)
1064 { 1080 {
1065 guchar *dest, *buf; 1081 guchar *dest, *buf;
1066 PurpleProxyConnectData *connect_data = data; 1082 PurpleProxyConnectData *connect_data = data;
1067 int len; 1083 int len;
1068 1084
1069 if (connect_data->read_buffer == NULL) { 1085 if (connect_data->read_buffer == NULL) {
1070 connect_data->read_buf_len = 512; 1086 connect_data->read_buf_len = 4;
1071 connect_data->read_buffer = g_malloc(connect_data->read_buf_len); 1087 connect_data->read_buffer = g_malloc(connect_data->read_buf_len);
1072 connect_data->read_len = 0; 1088 connect_data->read_len = 0;
1073 } 1089 }
1074 1090
1075 dest = connect_data->read_buffer + connect_data->read_len; 1091 dest = connect_data->read_buffer + connect_data->read_len;
1076 buf = connect_data->read_buffer; 1092 buf = connect_data->read_buffer;
1077
1078 purple_debug_info("socks5 proxy", "Able to read again.\n");
1079 1093
1080 len = read(connect_data->fd, dest, (connect_data->read_buf_len - connect_data->read_len)); 1094 len = read(connect_data->fd, dest, (connect_data->read_buf_len - connect_data->read_len));
1081 1095
1082 if (len == 0) 1096 if (len == 0)
1083 { 1097 {
1117 } 1131 }
1118 1132
1119 /* Skip past BND.ADDR */ 1133 /* Skip past BND.ADDR */
1120 switch(buf[3]) { 1134 switch(buf[3]) {
1121 case 0x01: /* the address is a version-4 IP address, with a length of 4 octets */ 1135 case 0x01: /* the address is a version-4 IP address, with a length of 4 octets */
1122 if(connect_data->read_len < 4 + 4) 1136 if(!s5_ensure_buffer_length(connect_data, 4 + 4))
1123 return; 1137 return;
1124 buf += 4 + 4; 1138 buf += 4 + 4;
1125 break; 1139 break;
1126 case 0x03: /* the address field contains a fully-qualified domain name. The first 1140 case 0x03: /* the address field contains a fully-qualified domain name. The first
1127 octet of the address field contains the number of octets of name that 1141 octet of the address field contains the number of octets of name that
1128 follow, there is no terminating NUL octet. */ 1142 follow, there is no terminating NUL octet. */
1129 if(connect_data->read_len < 4 + 1) 1143 if(!s5_ensure_buffer_length(connect_data, 4 + 1))
1130 return; 1144 return;
1131 buf += 4 + 1; 1145 buf += 4;
1132 if(connect_data->read_len < 4 + 1 + buf[0]) 1146 if(!s5_ensure_buffer_length(connect_data, 4 + 1 + buf[0]))
1133 return; 1147 return;
1134 buf += buf[0]; 1148 buf += buf[0] + 1;
1135 break; 1149 break;
1136 case 0x04: /* the address is a version-6 IP address, with a length of 16 octets */ 1150 case 0x04: /* the address is a version-6 IP address, with a length of 16 octets */
1137 if(connect_data->read_len < 4 + 16) 1151 if(!s5_ensure_buffer_length(connect_data, 4 + 16))
1138 return; 1152 return;
1139 buf += 4 + 16; 1153 buf += 4 + 16;
1140 break; 1154 break;
1141 } 1155 }
1142 1156
1143 if(connect_data->read_len < (buf - connect_data->read_buffer) + 2)
1144 return;
1145
1146 /* Skip past BND.PORT */ 1157 /* Skip past BND.PORT */
1147 buf += 2; 1158 if(!s5_ensure_buffer_length(connect_data, (buf - connect_data->read_buffer) + 2))
1159 return;
1148 1160
1149 purple_proxy_connect_data_connected(connect_data); 1161 purple_proxy_connect_data_connected(connect_data);
1150 } 1162 }
1151 1163
1152 static void 1164 static void