summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--opentracker.c44
-rw-r--r--ot_http.c6
-rw-r--r--ot_sync.c12
-rw-r--r--proxy.c8
4 files changed, 41 insertions, 29 deletions
diff --git a/opentracker.c b/opentracker.c
index f829171..bcc075c 100644
--- a/opentracker.c
+++ b/opentracker.c
@@ -7,9 +7,11 @@
7/* System */ 7/* System */
8#include <ctype.h> 8#include <ctype.h>
9#include <errno.h> 9#include <errno.h>
10#include <limits.h>
10#include <pthread.h> 11#include <pthread.h>
11#include <pwd.h> 12#include <pwd.h>
12#include <signal.h> 13#include <signal.h>
14#include <stdint.h>
13#include <stdio.h> 15#include <stdio.h>
14#include <stdlib.h> 16#include <stdlib.h>
15#include <string.h> 17#include <string.h>
@@ -23,7 +25,6 @@
23#include "io.h" 25#include "io.h"
24#include "iob.h" 26#include "iob.h"
25#include "ip6.h" 27#include "ip6.h"
26#include "scan.h"
27#include "socket.h" 28#include "socket.h"
28 29
29/* Opentracker */ 30/* Opentracker */
@@ -32,6 +33,7 @@
32#include "ot_http.h" 33#include "ot_http.h"
33#include "ot_livesync.h" 34#include "ot_livesync.h"
34#include "ot_mutex.h" 35#include "ot_mutex.h"
36#include "ot_scan.h"
35#include "ot_random.h" 37#include "ot_random.h"
36#include "ot_stats.h" 38#include "ot_stats.h"
37#include "ot_udp.h" 39#include "ot_udp.h"
@@ -380,8 +382,9 @@ char *set_config_option(char **option, char *value) {
380 return *option = strdup(value); 382 return *option = strdup(value);
381} 383}
382 384
383static int scan_ip6_port(const char *src, ot_ip6 ip, uint16 *port) { 385static int scan_ip6_port(const char *src, ot_ip6 ip, uint16_t *port) {
384 const char *s = src; 386 const char *s = src;
387 uint64_t value;
385 int off, bracket = 0; 388 int off, bracket = 0;
386 while (isspace(*s)) 389 while (isspace(*s))
387 ++s; 390 ++s;
@@ -404,13 +407,15 @@ static int scan_ip6_port(const char *src, ot_ip6 ip, uint16 *port) {
404 if (*(s++) != ':') 407 if (*(s++) != ':')
405 return 0; 408 return 0;
406 } 409 }
407 if (!(off = scan_ushort(s, port))) 410 if (!(off = scan_udec(s, &value, 65535)))
408 return 0; 411 return 0;
412 *port = (uint16_t)value;
409 return off + s - src; 413 return off + s - src;
410} 414}
411 415
412static int scan_ip6_net(const char *src, ot_net *net) { 416static int scan_ip6_net(const char *src, ot_net *net) {
413 const char *s = src; 417 const char *s = src;
418 uint64_t value;
414 int off; 419 int off;
415 while (isspace(*s)) 420 while (isspace(*s))
416 ++s; 421 ++s;
@@ -421,8 +426,9 @@ static int scan_ip6_net(const char *src, ot_net *net) {
421 net->bits = 128; 426 net->bits = 128;
422 else { 427 else {
423 s++; 428 s++;
424 if (!(off = scan_int(s, &net->bits))) 429 if (!(off = scan_udec(s, &value, 128)))
425 return 0; 430 return 0;
431 net->bits = (int)value;
426 if (ip6_isv4mapped(net->address)) 432 if (ip6_isv4mapped(net->address))
427 net->bits += 96; 433 net->bits += 96;
428 if (net->bits > 128) 434 if (net->bits > 128)
@@ -523,7 +529,8 @@ int parse_configfile(char *config_filename) {
523 } 529 }
524 530
525 while (fgets(inbuf, sizeof(inbuf), config_file_handle)) { 531 while (fgets(inbuf, sizeof(inbuf), config_file_handle)) {
526 char *p = inbuf, *end; 532 char *p = inbuf, *end;
533 uint64_t value;
527 uint16_t tmpport = 6969; 534 uint16_t tmpport = 6969;
528 535
529 /* Skip white spaces */ 536 /* Skip white spaces */
@@ -568,7 +575,8 @@ int parse_configfile(char *config_filename) {
568 ++bound; 575 ++bound;
569 break; 576 break;
570 case CONFIG_LISTEN_UDP_WORKERS: 577 case CONFIG_LISTEN_UDP_WORKERS:
571 scan_uint(p, &g_udp_workers); 578 if (scan_udec(p, &value, UINT_MAX))
579 g_udp_workers = (unsigned int)value;
572 break; 580 break;
573#ifdef WANT_ACCESSLIST_WHITE 581#ifdef WANT_ACCESSLIST_WHITE
574 case CONFIG_ACCESS_WHITELIST: 582 case CONFIG_ACCESS_WHITELIST:
@@ -634,9 +642,9 @@ int parse_configfile(char *config_filename) {
634void load_state(const char *const state_filename) { 642void load_state(const char *const state_filename) {
635 FILE *state_filehandle; 643 FILE *state_filehandle;
636 char inbuf[512]; 644 char inbuf[512];
637 ot_hash infohash; 645 ot_hash infohash;
638 unsigned long long base, downcount; 646 uint64_t base, downcount;
639 int consumed; 647 int consumed;
640 648
641 state_filehandle = fopen(state_filename, "r"); 649 state_filehandle = fopen(state_filename, "r");
642 650
@@ -653,10 +661,10 @@ void load_state(const char *const state_filename) {
653 continue; 661 continue;
654 i = 2 * sizeof(ot_hash); 662 i = 2 * sizeof(ot_hash);
655 663
656 if (inbuf[i++] != ':' || !(consumed = scan_ulonglong(inbuf + i, &base))) 664 if (inbuf[i++] != ':' || !(consumed = scan_udec(inbuf + i, &base, UINT64_MAX)))
657 continue; 665 continue;
658 i += consumed; 666 i += consumed;
659 if (inbuf[i++] != ':' || !(consumed = scan_ulonglong(inbuf + i, &downcount))) 667 if (inbuf[i++] != ':' || !(consumed = scan_udec(inbuf + i, &downcount, UINT64_MAX)))
660 continue; 668 continue;
661 add_torrent_from_saved_state(infohash, base, downcount); 669 add_torrent_from_saved_state(infohash, base, downcount);
662 } 670 }
@@ -725,7 +733,7 @@ int main(int argc, char **argv) {
725 ot_ip6 serverip; 733 ot_ip6 serverip;
726 ot_net tmpnet; 734 ot_net tmpnet;
727 int bound = 0, scanon = 1; 735 int bound = 0, scanon = 1;
728 uint16_t tmpport; 736 uint64_t value;
729 char *statefile = 0; 737 char *statefile = 0;
730 pthread_t thread_id; /* time cacher */ 738 pthread_t thread_id; /* time cacher */
731 739
@@ -764,28 +772,28 @@ int main(int argc, char **argv) {
764 break; 772 break;
765#endif 773#endif
766 case 'p': 774 case 'p':
767 if (!scan_ushort(optarg, &tmpport)) { 775 if (!scan_udec(optarg, &value, 65535)) {
768 usage(argv[0]); 776 usage(argv[0]);
769 exit(1); 777 exit(1);
770 } 778 }
771 ot_try_bind(serverip, tmpport, FLAG_TCP); 779 ot_try_bind(serverip, (uint16_t)value, FLAG_TCP);
772 bound++; 780 bound++;
773 break; 781 break;
774 case 'P': 782 case 'P':
775 if (!scan_ushort(optarg, &tmpport)) { 783 if (!scan_udec(optarg, &value, 65535)) {
776 usage(argv[0]); 784 usage(argv[0]);
777 exit(1); 785 exit(1);
778 } 786 }
779 ot_try_bind(serverip, tmpport, FLAG_UDP); 787 ot_try_bind(serverip, (uint16_t)value, FLAG_UDP);
780 bound++; 788 bound++;
781 break; 789 break;
782#ifdef WANT_SYNC_LIVE 790#ifdef WANT_SYNC_LIVE
783 case 's': 791 case 's':
784 if (!scan_ushort(optarg, &tmpport)) { 792 if (!scan_udec(optarg, &value, 65535)) {
785 usage(argv[0]); 793 usage(argv[0]);
786 exit(1); 794 exit(1);
787 } 795 }
788 livesync_bind_mcast(serverip, tmpport); 796 livesync_bind_mcast(serverip, (uint16_t)value);
789 break; 797 break;
790#endif 798#endif
791 case 'd': 799 case 'd':
diff --git a/ot_http.c b/ot_http.c
index 69bbc8e..626547b 100644
--- a/ot_http.c
+++ b/ot_http.c
@@ -18,7 +18,6 @@
18#include "array.h" 18#include "array.h"
19#include "iob.h" 19#include "iob.h"
20#include "ip6.h" 20#include "ip6.h"
21#include "scan.h"
22 21
23/* Opentracker */ 22/* Opentracker */
24#include "ot_accesslist.h" 23#include "ot_accesslist.h"
@@ -26,6 +25,7 @@
26#include "ot_http.h" 25#include "ot_http.h"
27#include "ot_iovec.h" 26#include "ot_iovec.h"
28#include "ot_mutex.h" 27#include "ot_mutex.h"
28#include "ot_scan.h"
29#include "ot_stats.h" 29#include "ot_stats.h"
30#include "scan_urlencoded_query.h" 30#include "scan_urlencoded_query.h"
31#include "trackerlogic.h" 31#include "trackerlogic.h"
@@ -618,6 +618,7 @@ static ssize_t http_handle_announce(const int64 sock, struct ot_workstruct *
618 // if( accesslist_is_blessed( cookie->ip, OT_PERMISSION_MAY_STAT ) ) { 618 // if( accesslist_is_blessed( cookie->ip, OT_PERMISSION_MAY_STAT ) ) {
619 char *tmp_buf = ws->reply; 619 char *tmp_buf = ws->reply;
620 ot_net net; 620 ot_net net;
621 uint64_t value;
621 signed short parsed, bits; 622 signed short parsed, bits;
622 623
623 len = scan_urlencoded_query(&read_ptr, tmp_buf, SCAN_SEARCHPATH_VALUE); 624 len = scan_urlencoded_query(&read_ptr, tmp_buf, SCAN_SEARCHPATH_VALUE);
@@ -634,9 +635,10 @@ static ssize_t http_handle_announce(const int64 sock, struct ot_workstruct *
634 if (tmp_buf[parsed++] != '/') 635 if (tmp_buf[parsed++] != '/')
635 bits = 128; 636 bits = 128;
636 else { 637 else {
637 parsed = scan_short(tmp_buf + parsed, &bits); 638 parsed = scan_udec(tmp_buf + parsed, &value, 128);
638 if (!parsed) 639 if (!parsed)
639 HTTPERROR_400_PARAM; 640 HTTPERROR_400_PARAM;
641 bits = (signed short)value;
640 if (ip6_isv4mapped(net.address)) 642 if (ip6_isv4mapped(net.address))
641 bits += 96; 643 bits += 96;
642 } 644 }
diff --git a/ot_sync.c b/ot_sync.c
index d3d30fa..fa6bb8b 100644
--- a/ot_sync.c
+++ b/ot_sync.c
@@ -12,11 +12,11 @@
12 12
13/* Libowfat */ 13/* Libowfat */
14#include "io.h" 14#include "io.h"
15#include "scan.h"
16 15
17/* Opentracker */ 16/* Opentracker */
18#include "ot_iovec.h" 17#include "ot_iovec.h"
19#include "ot_mutex.h" 18#include "ot_mutex.h"
19#include "ot_scan.h"
20#include "ot_stats.h" 20#include "ot_stats.h"
21#include "ot_sync.h" 21#include "ot_sync.h"
22#include "trackerlogic.h" 22#include "trackerlogic.h"
@@ -30,9 +30,9 @@
30 [..]: ( 20:01234567890abcdefghij16:XXXXYYYY )+ 30 [..]: ( 20:01234567890abcdefghij16:XXXXYYYY )+
31*/ 31*/
32int add_changeset_to_tracker(uint8_t *data, size_t len) { 32int add_changeset_to_tracker(uint8_t *data, size_t len) {
33 ot_hash *hash; 33 ot_hash *hash;
34 uint8_t *end = data + len; 34 uint8_t *end = data + len;
35 unsigned long peer_count; 35 uint64_t peer_count;
36 36
37 /* We do know, that the string is \n terminated, so it can't 37 /* We do know, that the string is \n terminated, so it can't
38 overflow */ 38 overflow */
@@ -50,8 +50,8 @@ int add_changeset_to_tracker(uint8_t *data, size_t len) {
50 hash = (ot_hash *)data; 50 hash = (ot_hash *)data;
51 data += sizeof(ot_hash); 51 data += sizeof(ot_hash);
52 52
53 /* Scan string length indicator */ 53 /* Scan string length indicator, strictly: bencode writes no leading zeros */
54 data += (len = scan_ulong((char *)data, &peer_count)); 54 data += (len = scan_udec_bencode((char *)data, &peer_count, (uint64_t)(end - data)));
55 55
56 /* If no long was scanned, it is not divisible by 8, it is not 56 /* If no long was scanned, it is not divisible by 8, it is not
57 followed by a colon or claims to need to much memory, we fail */ 57 followed by a colon or claims to need to much memory, we fail */
diff --git a/proxy.c b/proxy.c
index ec51630..19a084a 100644
--- a/proxy.c
+++ b/proxy.c
@@ -20,11 +20,11 @@
20#include "io.h" 20#include "io.h"
21#include "iob.h" 21#include "iob.h"
22#include "ip6.h" 22#include "ip6.h"
23#include "scan.h"
24#include "socket.h" 23#include "socket.h"
25 24
26/* Opentracker */ 25/* Opentracker */
27#include "ot_mutex.h" 26#include "ot_mutex.h"
27#include "ot_scan.h"
28#include "ot_random.h" 28#include "ot_random.h"
29#include "ot_stats.h" 29#include "ot_stats.h"
30#include "ot_vector.h" 30#include "ot_vector.h"
@@ -531,8 +531,9 @@ static int64_t ot_try_bind(ot_ip6 ip, uint16_t port) {
531 return sock; 531 return sock;
532} 532}
533 533
534static int scan_ip6_port(const char *src, ot_ip6 ip, uint16 *port) { 534static int scan_ip6_port(const char *src, ot_ip6 ip, uint16_t *port) {
535 const char *s = src; 535 const char *s = src;
536 uint64_t value;
536 int off, bracket = 0; 537 int off, bracket = 0;
537 while (isspace(*s)) 538 while (isspace(*s))
538 ++s; 539 ++s;
@@ -553,8 +554,9 @@ static int scan_ip6_port(const char *src, ot_ip6 ip, uint16 *port) {
553 if (*(s++) != ':') 554 if (*(s++) != ':')
554 return 0; 555 return 0;
555 } 556 }
556 if (!(off = scan_ushort(s, port))) 557 if (!(off = scan_udec(s, &value, 65535)))
557 return 0; 558 return 0;
559 *port = (uint16_t)value;
558 return off + s - src; 560 return off + s - src;
559} 561}
560 562