View | Details | Raw Unified | Return to bug 97408
Collapse All | Expand All

(-)ekg-1.6rc1/lib/common.c (-8 / +15 lines)
Lines 294-305 Link Here
294
 *  - buf - wska¼nik do bufora
294
 *  - buf - wska¼nik do bufora
295
 *  - length - d³ugo¶æ bufora
295
 *  - length - d³ugo¶æ bufora
296
 *
296
 *
297
 * je¶li trafi na b³±d odczytu, zwraca NULL. inaczej zwraca buf.
297
 * je¶li trafi na b³±d odczytu lub podano nieprawid³owe parametry, zwraca NULL.
298
 * inaczej zwraca buf.
298
 */
299
 */
299
char *gg_read_line(int sock, char *buf, int length)
300
char *gg_read_line(int sock, char *buf, int length)
300
{
301
{
301
	int ret;
302
	int ret;
302
303
304
	if (!buf || length < 0)
305
		return NULL;
306
303
	for (; length > 1; buf++, length--) {
307
	for (; length > 1; buf++, length--) {
304
		do {
308
		do {
305
			if ((ret = read(sock, buf, 1)) == -1 && errno != EINTR) {
309
			if ((ret = read(sock, buf, 1)) == -1 && errno != EINTR) {
Lines 360-366 Link Here
360
{
364
{
361
	char *q, *buf, hex[] = "0123456789abcdef";
365
	char *q, *buf, hex[] = "0123456789abcdef";
362
	const char *p;
366
	const char *p;
363
	int size = 0;
367
	unsigned int size = 0;
364
368
365
	if (!str)
369
	if (!str)
366
		str = "";
370
		str = "";
Lines 412-429 Link Here
412
	va_start(ap, format);
416
	va_start(ap, format);
413
417
414
	for (j = 0; j < strlen(format); j++) {
418
	for (j = 0; j < strlen(format); j++) {
415
		unsigned char *arg, buf[16];
419
		char *arg, buf[16];
416
420
417
		if (format[j] == 'u') {
421
		if (format[j] == 'u') {
418
			snprintf(buf, sizeof(buf), "%d", va_arg(ap, uin_t));
422
			snprintf(buf, sizeof(buf), "%d", va_arg(ap, uin_t));
419
			arg = buf;
423
			arg = buf;
420
		} else {
424
		} else {
421
			if (!(arg = va_arg(ap, unsigned char*)))
425
			if (!(arg = va_arg(ap, char*)))
422
				arg = "";
426
				arg = "";
423
		}	
427
		}	
424
428
425
		i = 0;
429
		i = 0;
426
		while ((c = (int) arg[i++]) != 0) {
430
		while ((c = (unsigned char) arg[i++]) != 0) {
427
			a = (c ^ b) + (c << 8);
431
			a = (c ^ b) + (c << 8);
428
			b = (a >> 24) | (a << 8);
432
			b = (a >> 24) | (a << 8);
429
		}
433
		}
Lines 613-619 Link Here
613
char *gg_base64_encode(const char *buf)
617
char *gg_base64_encode(const char *buf)
614
{
618
{
615
	char *out, *res;
619
	char *out, *res;
616
	int i = 0, j = 0, k = 0, len = strlen(buf);
620
	unsigned int i = 0, j = 0, k = 0, len = strlen(buf);
617
	
621
	
618
	res = out = malloc((len / 3 + 1) * 4 + 2);
622
	res = out = malloc((len / 3 + 1) * 4 + 2);
619
623
Lines 671-677 Link Here
671
{
675
{
672
	char *res, *save, *foo, val;
676
	char *res, *save, *foo, val;
673
	const char *end;
677
	const char *end;
674
	int index = 0;
678
	unsigned int index = 0;
675
679
676
	if (!buf)
680
	if (!buf)
677
		return NULL;
681
		return NULL;
Lines 765-771 Link Here
765
static void gg_crc32_make_table()
769
static void gg_crc32_make_table()
766
{
770
{
767
	uint32_t h = 1;
771
	uint32_t h = 1;
768
	int i, j;
772
	unsigned int i, j;
769
773
770
	memset(gg_crc32_table, 0, sizeof(gg_crc32_table));
774
	memset(gg_crc32_table, 0, sizeof(gg_crc32_table));
771
775
Lines 795-800 Link Here
795
	if (!gg_crc32_initialized)
799
	if (!gg_crc32_initialized)
796
		gg_crc32_make_table();
800
		gg_crc32_make_table();
797
801
802
	if (!buf || len < 0)
803
		return crc;
804
798
	crc ^= 0xffffffffL;
805
	crc ^= 0xffffffffL;
799
806
800
	while (len--)
807
	while (len--)
(-)ekg-1.6rc1/lib/dcc.c (-2 / +2 lines)
Lines 52-60 Link Here
52
 *  - buf - bufor z danymi
52
 *  - buf - bufor z danymi
53
 *  - size - rozmiar danych
53
 *  - size - rozmiar danych
54
 */
54
 */
55
static void gg_dcc_debug_data(const char *prefix, int fd, const void *buf, int size)
55
static void gg_dcc_debug_data(const char *prefix, int fd, const void *buf, unsigned int size)
56
{
56
{
57
	int i;
57
	unsigned int i;
58
	
58
	
59
	gg_debug(GG_DEBUG_MISC, "++ gg_dcc %s (fd=%d,len=%d)", prefix, fd, size);
59
	gg_debug(GG_DEBUG_MISC, "++ gg_dcc %s (fd=%d,len=%d)", prefix, fd, size);
60
	
60
	
(-)ekg-1.6rc1/lib/events.c (-15 / +25 lines)
Lines 167-179 Link Here
167
 *  - e - opis zdarzenia
167
 *  - e - opis zdarzenia
168
 *  - 
168
 *  - 
169
 */
169
 */
170
static void gg_image_queue_parse(struct gg_event *e, char *p, int len, struct gg_session *sess, uin_t sender)
170
static void gg_image_queue_parse(struct gg_event *e, char *p, unsigned int len, struct gg_session *sess, uin_t sender)
171
{
171
{
172
	struct gg_msg_image_reply *i = (void*) p;
172
	struct gg_msg_image_reply *i = (void*) p;
173
	struct gg_image_queue *q, *qq;
173
	struct gg_image_queue *q, *qq;
174
174
175
	if (!p || !sess || !e)
175
	if (!p || !sess || !e) {
176
	{
177
		errno = EFAULT;
176
		errno = EFAULT;
178
		return;
177
		return;
179
	}
178
	}
Lines 302-308 Link Here
302
301
303
				count = gg_fix32(m->count);
302
				count = gg_fix32(m->count);
304
303
305
				if (p + count * sizeof(uin_t) > packet_end) {
304
				if (p + count * sizeof(uin_t) > packet_end || p + count * sizeof(uin_t) < p || count > 0xffff) {
306
					gg_debug(GG_DEBUG_MISC, "// gg_handle_recv_msg() packet out of bounds (1.5)\n");
305
					gg_debug(GG_DEBUG_MISC, "// gg_handle_recv_msg() packet out of bounds (1.5)\n");
307
					goto malformed;
306
					goto malformed;
308
				}
307
				}
Lines 312-319 Link Here
312
					goto fail;
311
					goto fail;
313
				}
312
				}
314
			
313
			
315
				for (i = 0; i < count; i++, p += sizeof(uin_t))
314
				for (i = 0; i < count; i++, p += sizeof(uint32_t)) {
316
					e->event.msg.recipients[i] = gg_fix32(*((uint32_t*) p));
315
					uint32_t u;
316
					memcpy(&u, p, sizeof(uint32_t));
317
					e->event.msg.recipients[i] = gg_fix32(u);
318
				}
317
				
319
				
318
				e->event.msg.recipients_count = count;
320
				e->event.msg.recipients_count = count;
319
				
321
				
Lines 322-328 Link Here
322
324
323
			case 0x02:		/* richtext */
325
			case 0x02:		/* richtext */
324
			{
326
			{
325
				unsigned short len;
327
				uint16_t len;
326
				char *buf;
328
				char *buf;
327
			
329
			
328
				if (p + 3 > packet_end) {
330
				if (p + 3 > packet_end) {
Lines 330-336 Link Here
330
					goto malformed;
332
					goto malformed;
331
				}
333
				}
332
334
333
				len = gg_fix16(*((unsigned short*) (p + 1)));
335
				memcpy(&len, p + 1, sizeof(uint16_t));
336
				len = gg_fix16(len);
334
337
335
				if (!(buf = malloc(len))) {
338
				if (!(buf = malloc(len))) {
336
					gg_debug(GG_DEBUG_MISC, "// gg_handle_recv_msg() not enough memory for richtext data\n");
339
					gg_debug(GG_DEBUG_MISC, "// gg_handle_recv_msg() not enough memory for richtext data\n");
Lines 394-400 Link Here
394
					goto malformed;
399
					goto malformed;
395
				}
400
				}
396
401
397
				gg_image_queue_parse(e, p, (int)(packet_end - p), sess, gg_fix32(r->sender));
402
				rep->size = gg_fix32(rep->size);
403
				rep->crc32 = gg_fix32(rep->crc32);
404
				gg_image_queue_parse(e, p, (unsigned int)(packet_end - p), sess, gg_fix32(r->sender));
398
405
399
				return 0;
406
				return 0;
400
			}
407
			}
Lines 471-477 Link Here
471
		case GG_NOTIFY_REPLY:
478
		case GG_NOTIFY_REPLY:
472
		{
479
		{
473
			struct gg_notify_reply *n = (void*) p;
480
			struct gg_notify_reply *n = (void*) p;
474
			int count, i;
481
			unsigned int count, i;
475
			char *tmp;
482
			char *tmp;
476
483
477
			gg_debug(GG_DEBUG_MISC, "// gg_watch_fd_connected() received a notify reply\n");
484
			gg_debug(GG_DEBUG_MISC, "// gg_watch_fd_connected() received a notify reply\n");
Lines 482-488 Link Here
482
				goto fail;
489
				goto fail;
483
			}
490
			}
484
491
485
			if (gg_fix32(n->status) == GG_STATUS_BUSY_DESCR || gg_fix32(n->status == GG_STATUS_NOT_AVAIL_DESCR) || gg_fix32(n->status) == GG_STATUS_AVAIL_DESCR) {
492
			if (gg_fix32(n->status) == GG_STATUS_BUSY_DESCR || gg_fix32(n->status) == GG_STATUS_NOT_AVAIL_DESCR || gg_fix32(n->status) == GG_STATUS_AVAIL_DESCR) {
486
				e->type = GG_EVENT_NOTIFY_DESCR;
493
				e->type = GG_EVENT_NOTIFY_DESCR;
487
				
494
				
488
				if (!(e->event.notify_descr.notify = (void*) malloc(sizeof(*n) * 2))) {
495
				if (!(e->event.notify_descr.notify = (void*) malloc(sizeof(*n) * 2))) {
Lines 493-498 Link Here
493
				memcpy(e->event.notify_descr.notify, p, sizeof(*n));
500
				memcpy(e->event.notify_descr.notify, p, sizeof(*n));
494
				e->event.notify_descr.notify[0].uin = gg_fix32(e->event.notify_descr.notify[0].uin);
501
				e->event.notify_descr.notify[0].uin = gg_fix32(e->event.notify_descr.notify[0].uin);
495
				e->event.notify_descr.notify[0].status = gg_fix32(e->event.notify_descr.notify[0].status);
502
				e->event.notify_descr.notify[0].status = gg_fix32(e->event.notify_descr.notify[0].status);
503
				e->event.notify_descr.notify[0].remote_ip = e->event.notify_descr.notify[0].remote_ip;
496
				e->event.notify_descr.notify[0].remote_port = gg_fix16(e->event.notify_descr.notify[0].remote_port);
504
				e->event.notify_descr.notify[0].remote_port = gg_fix16(e->event.notify_descr.notify[0].remote_port);
497
505
498
				count = h->length - sizeof(*n);
506
				count = h->length - sizeof(*n);
Lines 519-525 Link Here
519
				for (i = 0; i < count; i++) {
527
				for (i = 0; i < count; i++) {
520
					e->event.notify[i].uin = gg_fix32(e->event.notify[i].uin);
528
					e->event.notify[i].uin = gg_fix32(e->event.notify[i].uin);
521
					e->event.notify[i].status = gg_fix32(e->event.notify[i].status);
529
					e->event.notify[i].status = gg_fix32(e->event.notify[i].status);
522
					e->event.notify[i].remote_port = gg_fix16(e->event.notify[i].remote_port);		
530
					e->event.notify[i].remote_ip = e->event.notify[i].remote_ip;
531
					e->event.notify[i].remote_port = gg_fix16(e->event.notify[i].remote_port);
523
				}
532
				}
524
			}
533
			}
525
534
Lines 653-660 Link Here
653
669
654
				e->event.status60.descr = buf;
670
				e->event.status60.descr = buf;
655
671
656
				if (len > 4 && p[h->length - 5] == 0)
672
				if (len > 4 && p[h->length - 5] == 0) {
657
					e->event.status60.time = *((int*) (p + h->length - 4));
673
					uint32_t t;
674
					memcpy(&t, p + h->length - 4, sizeof(uint32_t));
675
					e->event.status60.time = gg_fix32(t);
676
				}
658
			}
677
			}
659
678
660
			break;
679
			break;
Lines 720-726 Link Here
720
739
721
			if (h->length > 1) {
740
			if (h->length > 1) {
722
				char *tmp;
741
				char *tmp;
723
				int len = (sess->userlist_reply) ? strlen(sess->userlist_reply) : 0;
742
				unsigned int len = (sess->userlist_reply) ? strlen(sess->userlist_reply) : 0;
724
				
743
				
725
				gg_debug(GG_DEBUG_MISC, "userlist_reply=%p, len=%d\n", sess->userlist_reply, len);
744
				gg_debug(GG_DEBUG_MISC, "userlist_reply=%p, len=%d\n", sess->userlist_reply, len);
726
				
745
				
(-)ekg-1.6rc1/lib/http.c (-3 / +3 lines)
Lines 243-249 Link Here
243
	}
243
	}
244
244
245
	if (h->state == GG_STATE_SENDING_QUERY) {
245
	if (h->state == GG_STATE_SENDING_QUERY) {
246
		unsigned int res;
246
		int res;
247
247
248
		if ((res = write(h->fd, h->query, strlen(h->query))) < 1) {
248
		if ((res = write(h->fd, h->query, strlen(h->query))) < 1) {
249
			gg_debug(GG_DEBUG_MISC, "=> http, write() failed (len=%d, res=%d, errno=%d)\n", strlen(h->query), res, errno);
249
			gg_debug(GG_DEBUG_MISC, "=> http, write() failed (len=%d, res=%d, errno=%d)\n", strlen(h->query), res, errno);
Lines 272-278 Link Here
272
272
273
	if (h->state == GG_STATE_READING_HEADER) {
273
	if (h->state == GG_STATE_READING_HEADER) {
274
		char buf[1024], *tmp;
274
		char buf[1024], *tmp;
275
		unsigned int res;
275
		int res;
276
276
277
		if ((res = read(h->fd, buf, sizeof(buf))) == -1) {
277
		if ((res = read(h->fd, buf, sizeof(buf))) == -1) {
278
			gg_debug(GG_DEBUG_MISC, "=> http, reading header failed (errno=%d)\n", errno);
278
			gg_debug(GG_DEBUG_MISC, "=> http, reading header failed (errno=%d)\n", errno);
Lines 380-386 Link Here
380
380
381
	if (h->state == GG_STATE_READING_DATA) {
381
	if (h->state == GG_STATE_READING_DATA) {
382
		char buf[1024];
382
		char buf[1024];
383
		unsigned int res;
383
		int res;
384
384
385
		if ((res = read(h->fd, buf, sizeof(buf))) == -1) {
385
		if ((res = read(h->fd, buf, sizeof(buf))) == -1) {
386
			gg_debug(GG_DEBUG_MISC, "=> http, reading body failed (errno=%d)\n", errno);
386
			gg_debug(GG_DEBUG_MISC, "=> http, reading body failed (errno=%d)\n", errno);
(-)ekg-1.6rc1/lib/libgadu.c (-11 / +20 lines)
Lines 455-467 Link Here
455
 *
455
 *
456
 *  - sess - opis sesji
456
 *  - sess - opis sesji
457
 *
457
 *
458
 * w przypadku b³êdu NULL, kod b³êdu w errno.
458
 * w przypadku b³êdu NULL, kod b³êdu w errno. nale¿y zwróciæ uwagê, ¿e gdy
459
 * po³±czenie jest nieblokuj±ce, a kod b³êdu wynosi EAGAIN, nie uda³o siê
460
 * odczytaæ ca³ego pakietu i nie nale¿y tego traktowaæ jako b³±d.
459
 */
461
 */
460
void *gg_recv_packet(struct gg_session *sess)
462
void *gg_recv_packet(struct gg_session *sess)
461
{
463
{
462
	struct gg_header h;
464
	struct gg_header h;
463
	char *buf = NULL;
465
	char *buf = NULL;
464
	int ret = 0, offset, size = 0;
466
	int ret = 0;
467
	unsigned int offset, size = 0;
465
468
466
	gg_debug(GG_DEBUG_FUNCTION, "** gg_recv_packet(%p);\n", sess);
469
	gg_debug(GG_DEBUG_FUNCTION, "** gg_recv_packet(%p);\n", sess);
467
	
470
	
Lines 485-491 Link Here
485
			gg_debug(GG_DEBUG_MISC, "// gg_recv_packet() header recv(%d,%p,%d) = %d\n", sess->fd, &h + sess->header_done, sizeof(h) - sess->header_done, ret);
488
			gg_debug(GG_DEBUG_MISC, "// gg_recv_packet() header recv(%d,%p,%d) = %d\n", sess->fd, &h + sess->header_done, sizeof(h) - sess->header_done, ret);
486
489
487
			if (!ret) {
490
			if (!ret) {
488
				errno = 0;
491
				errno = ECONNRESET;
489
				gg_debug(GG_DEBUG_MISC, "// gg_recv_packet() header recv() failed: connection broken\n");
492
				gg_debug(GG_DEBUG_MISC, "// gg_recv_packet() header recv() failed: connection broken\n");
490
				return NULL;
493
				return NULL;
491
			}
494
			}
Lines 524-530 Link Here
524
		memcpy(&h, sess->recv_buf, sizeof(h));
527
		memcpy(&h, sess->recv_buf, sizeof(h));
525
	
528
	
526
	/* jakie¶ sensowne limity na rozmiar pakietu */
529
	/* jakie¶ sensowne limity na rozmiar pakietu */
527
	if (h.length < 0 || h.length > 65535) {
530
	if (h.length > 65535) {
528
		gg_debug(GG_DEBUG_MISC, "// gg_recv_packet() invalid packet length (%d)\n", h.length);
531
		gg_debug(GG_DEBUG_MISC, "// gg_recv_packet() invalid packet length (%d)\n", h.length);
529
		errno = ERANGE;
532
		errno = ERANGE;
530
		return NULL;
533
		return NULL;
Lines 550-560 Link Here
550
	while (size > 0) {
553
	while (size > 0) {
551
		ret = gg_read(sess, buf + sizeof(h) + offset, size);
554
		ret = gg_read(sess, buf + sizeof(h) + offset, size);
552
		gg_debug(GG_DEBUG_MISC, "// gg_recv_packet() body recv(%d,%p,%d) = %d\n", sess->fd, buf + sizeof(h) + offset, size, ret);
555
		gg_debug(GG_DEBUG_MISC, "// gg_recv_packet() body recv(%d,%p,%d) = %d\n", sess->fd, buf + sizeof(h) + offset, size, ret);
556
		if (!ret) {
557
			gg_debug(GG_DEBUG_MISC, "// gg_recv_packet() body recv() failed: connection broken\n");
558
			errno = ECONNRESET;
559
			return NULL;
560
		}
553
		if (ret > -1 && ret <= size) {
561
		if (ret > -1 && ret <= size) {
554
			offset += ret;
562
			offset += ret;
555
			size -= ret;
563
			size -= ret;
556
		} else if (ret == -1) {	
564
		} else if (ret == -1) {	
565
			int errno2 = errno;
566
557
			gg_debug(GG_DEBUG_MISC, "// gg_recv_packet() body recv() failed (errno=%d, %s)\n", errno, strerror(errno));
567
			gg_debug(GG_DEBUG_MISC, "// gg_recv_packet() body recv() failed (errno=%d, %s)\n", errno, strerror(errno));
568
			errno = errno2;
569
558
			if (errno == EAGAIN) {
570
			if (errno == EAGAIN) {
559
				gg_debug(GG_DEBUG_MISC, "// gg_recv_packet() %d bytes received, %d left\n", offset, size);
571
				gg_debug(GG_DEBUG_MISC, "// gg_recv_packet() %d bytes received, %d left\n", offset, size);
560
				sess->recv_buf = buf;
572
				sess->recv_buf = buf;
Lines 605-613 Link Here
605
{
617
{
606
	struct gg_header *h;
618
	struct gg_header *h;
607
	char *tmp;
619
	char *tmp;
608
	int tmp_length;
620
	unsigned int tmp_length;
609
	void *payload;
621
	void *payload;
610
	int payload_length;
622
	unsigned int payload_length;
611
	va_list ap;
623
	va_list ap;
612
	int res;
624
	int res;
613
625
Lines 627-637 Link Here
627
	while (payload) {
639
	while (payload) {
628
		char *tmp2;
640
		char *tmp2;
629
641
630
		payload_length = va_arg(ap, int);
642
		payload_length = va_arg(ap, unsigned int);
631
643
632
		if (payload_length < 0)
633
			gg_debug(GG_DEBUG_MISC, "// gg_send_packet() invalid payload length (%d)\n", payload_length);
634
	
635
		if (!(tmp2 = realloc(tmp, tmp_length + payload_length))) {
644
		if (!(tmp2 = realloc(tmp, tmp_length + payload_length))) {
636
			gg_debug(GG_DEBUG_MISC, "// gg_send_packet() not enough memory for payload\n");
645
			gg_debug(GG_DEBUG_MISC, "// gg_send_packet() not enough memory for payload\n");
637
			free(tmp);
646
			free(tmp);
Lines 1435-1441 Link Here
1435
		return -1;
1446
		return -1;
1436
	}
1447
	}
1437
1448
1438
	if (!message || recipients_count <= 0 || !recipients) {
1449
	if (!message || recipients_count <= 0 || recipients_count > 0xffff || !recipients) {
1439
		errno = EINVAL;
1450
		errno = EINVAL;
1440
		return -1;
1451
		return -1;
1441
	}
1452
	}

Return to bug 97408