comparison src/protocols/yahoo/yahoo.c @ 3996:3fdfe7872118

[gaim-migrate @ 4191] - Fixed a segfault that occurred when a key/value pair had no value (i.e., in the mail notification packets that the Yahoo server is sending out). - Skip over a garbage character in mail notification packets that's causing the sender name key/value pair to be ignored. - Some code cleanups, which should optimize it (though not noticeably so) and make it easier to read. Thanks go to ZuperDee for this. Hope this works for everybody else. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Sat, 23 Nov 2002 11:08:11 +0000
parents f53370197bb9
children 9178da61c19f
comparison
equal deleted inserted replaced
3995:544e48c05f61 3996:3fdfe7872118
266 key[x] = 0; 266 key[x] = 0;
267 pos += 2; 267 pos += 2;
268 pair->key = strtol(key, NULL, 10); 268 pair->key = strtol(key, NULL, 10);
269 accept = x; /* if x is 0 there was no key, so don't accept it */ 269 accept = x; /* if x is 0 there was no key, so don't accept it */
270 270
271 if (accept) 271 if (len - pos + 1 <= 0) {
272 /* Truncated. Garbage or something. */
273 accept = 0;
274 }
275
276 if (accept) {
272 value = g_malloc(len - pos + 1); 277 value = g_malloc(len - pos + 1);
273 x = 0; 278 x = 0;
274 while (pos + 1 < len) { 279 while (pos + 1 < len) {
275 if (data[pos] == 0xc0 && data[pos + 1] == 0x80) 280 if (data[pos] == 0xc0 && data[pos + 1] == 0x80)
276 break; 281 break;
277 if (accept)
278 value[x++] = data[pos++]; 282 value[x++] = data[pos++];
279 } 283 }
280 if (accept)
281 value[x] = 0; 284 value[x] = 0;
282 pos += 2;
283 if (accept) {
284 pair->value = g_strdup(value); 285 pair->value = g_strdup(value);
285 g_free(value); 286 g_free(value);
286 pkt->hash = g_slist_append(pkt->hash, pair); 287 pkt->hash = g_slist_append(pkt->hash, pair);
287 debug_printf("Key: %d \tValue: %s\n", pair->key, pair->value); 288 debug_printf("Key: %d \tValue: %s\n", pair->key, pair->value);
288 } else { 289 } else {
289 g_free(pair); 290 g_free(pair);
290 } 291 }
292 pos += 2;
293
294 /* Skip over garbage we've noticed in the mail notifications */
295 if (data[0] == '9' && data[pos] == 0x01)
296 pos++;
291 } 297 }
292 } 298 }
293 299
294 static void yahoo_packet_write(struct yahoo_packet *pkt, guchar *data) 300 static void yahoo_packet_write(struct yahoo_packet *pkt, guchar *data)
295 { 301 {