From 248bf17de8a25c741393b28e75c4e5380947792c Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Sat, 24 Oct 2026 05:27:59 +0200 Subject: Use new ranged unsigned int scanner everywhere and squash some bugs along the way --- opentracker.c | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) (limited to 'opentracker.c') diff --git a/opentracker.c b/opentracker.c index f829171..bcc075c 100644 --- a/opentracker.c +++ b/opentracker.c @@ -7,9 +7,11 @@ /* System */ #include #include +#include #include #include #include +#include #include #include #include @@ -23,7 +25,6 @@ #include "io.h" #include "iob.h" #include "ip6.h" -#include "scan.h" #include "socket.h" /* Opentracker */ @@ -32,6 +33,7 @@ #include "ot_http.h" #include "ot_livesync.h" #include "ot_mutex.h" +#include "ot_scan.h" #include "ot_random.h" #include "ot_stats.h" #include "ot_udp.h" @@ -380,8 +382,9 @@ char *set_config_option(char **option, char *value) { return *option = strdup(value); } -static int scan_ip6_port(const char *src, ot_ip6 ip, uint16 *port) { +static int scan_ip6_port(const char *src, ot_ip6 ip, uint16_t *port) { const char *s = src; + uint64_t value; int off, bracket = 0; while (isspace(*s)) ++s; @@ -404,13 +407,15 @@ static int scan_ip6_port(const char *src, ot_ip6 ip, uint16 *port) { if (*(s++) != ':') return 0; } - if (!(off = scan_ushort(s, port))) + if (!(off = scan_udec(s, &value, 65535))) return 0; + *port = (uint16_t)value; return off + s - src; } static int scan_ip6_net(const char *src, ot_net *net) { const char *s = src; + uint64_t value; int off; while (isspace(*s)) ++s; @@ -421,8 +426,9 @@ static int scan_ip6_net(const char *src, ot_net *net) { net->bits = 128; else { s++; - if (!(off = scan_int(s, &net->bits))) + if (!(off = scan_udec(s, &value, 128))) return 0; + net->bits = (int)value; if (ip6_isv4mapped(net->address)) net->bits += 96; if (net->bits > 128) @@ -523,7 +529,8 @@ int parse_configfile(char *config_filename) { } while (fgets(inbuf, sizeof(inbuf), config_file_handle)) { - char *p = inbuf, *end; + char *p = inbuf, *end; + uint64_t value; uint16_t tmpport = 6969; /* Skip white spaces */ @@ -568,7 +575,8 @@ int parse_configfile(char *config_filename) { ++bound; break; case CONFIG_LISTEN_UDP_WORKERS: - scan_uint(p, &g_udp_workers); + if (scan_udec(p, &value, UINT_MAX)) + g_udp_workers = (unsigned int)value; break; #ifdef WANT_ACCESSLIST_WHITE case CONFIG_ACCESS_WHITELIST: @@ -634,9 +642,9 @@ int parse_configfile(char *config_filename) { void load_state(const char *const state_filename) { FILE *state_filehandle; char inbuf[512]; - ot_hash infohash; - unsigned long long base, downcount; - int consumed; + ot_hash infohash; + uint64_t base, downcount; + int consumed; state_filehandle = fopen(state_filename, "r"); @@ -653,10 +661,10 @@ void load_state(const char *const state_filename) { continue; i = 2 * sizeof(ot_hash); - if (inbuf[i++] != ':' || !(consumed = scan_ulonglong(inbuf + i, &base))) + if (inbuf[i++] != ':' || !(consumed = scan_udec(inbuf + i, &base, UINT64_MAX))) continue; i += consumed; - if (inbuf[i++] != ':' || !(consumed = scan_ulonglong(inbuf + i, &downcount))) + if (inbuf[i++] != ':' || !(consumed = scan_udec(inbuf + i, &downcount, UINT64_MAX))) continue; add_torrent_from_saved_state(infohash, base, downcount); } @@ -725,7 +733,7 @@ int main(int argc, char **argv) { ot_ip6 serverip; ot_net tmpnet; int bound = 0, scanon = 1; - uint16_t tmpport; + uint64_t value; char *statefile = 0; pthread_t thread_id; /* time cacher */ @@ -764,28 +772,28 @@ int main(int argc, char **argv) { break; #endif case 'p': - if (!scan_ushort(optarg, &tmpport)) { + if (!scan_udec(optarg, &value, 65535)) { usage(argv[0]); exit(1); } - ot_try_bind(serverip, tmpport, FLAG_TCP); + ot_try_bind(serverip, (uint16_t)value, FLAG_TCP); bound++; break; case 'P': - if (!scan_ushort(optarg, &tmpport)) { + if (!scan_udec(optarg, &value, 65535)) { usage(argv[0]); exit(1); } - ot_try_bind(serverip, tmpport, FLAG_UDP); + ot_try_bind(serverip, (uint16_t)value, FLAG_UDP); bound++; break; #ifdef WANT_SYNC_LIVE case 's': - if (!scan_ushort(optarg, &tmpport)) { + if (!scan_udec(optarg, &value, 65535)) { usage(argv[0]); exit(1); } - livesync_bind_mcast(serverip, tmpport); + livesync_bind_mcast(serverip, (uint16_t)value); break; #endif case 'd': -- cgit v1.3