diff options
author | Anton Luka Šijanec <anton@sijanec.eu> | 2023-01-30 17:27:57 +0100 |
---|---|---|
committer | Anton Luka Šijanec <anton@sijanec.eu> | 2023-01-30 17:27:57 +0100 |
commit | c6156989725399a83f4a33384a3c60885ed6f211 (patch) | |
tree | 842d3fb0e54e1f5c8ccaf1941dc8caf8a8863c6a /src/dht.c | |
parent | fix use after free in torrent structs (diff) | |
download | travnik-c6156989725399a83f4a33384a3c60885ed6f211.tar travnik-c6156989725399a83f4a33384a3c60885ed6f211.tar.gz travnik-c6156989725399a83f4a33384a3c60885ed6f211.tar.bz2 travnik-c6156989725399a83f4a33384a3c60885ed6f211.tar.lz travnik-c6156989725399a83f4a33384a3c60885ed6f211.tar.xz travnik-c6156989725399a83f4a33384a3c60885ed6f211.tar.zst travnik-c6156989725399a83f4a33384a3c60885ed6f211.zip |
Diffstat (limited to '')
-rw-r--r-- | src/dht.c | 27 |
1 files changed, 17 insertions, 10 deletions
@@ -428,7 +428,7 @@ void torrent_print (FILE * s, const struct torrent * t) { char buf[41]; buf[40] = '\0'; bin2hex(buf, t->hash, 20); - printf("magnet:?xt=urn:btih:%s%s%s%s%s%s%s%s\n\t**** PEERS ****\n", buf, t->type & announce ? " announce" : "", t->type & peers ? " peers" : "", t->type & info ? " info" : "", t->state & handshake_sent ? " handshake_sent" : "", t->state & handshake_received ? " handshake_received" : "", t->state & extension_sent ? " extension_sent" : "", t->state & extension_received ? " extension_received" : ""); + printf("magnet:?xt=urn:btih:%s%s%s%s%s%s%s%s ttl=%ld\n\t**** PEERS ****\n", buf, t->type & announce ? " announce" : "", t->type & peers ? " peers" : "", t->type & info ? " info" : "", t->state & handshake_sent ? " handshake_sent" : "", t->state & handshake_received ? " handshake_received" : "", t->state & extension_sent ? " extension_sent" : "", t->state & extension_received ? " extension_received" : "", t->ttl > 0 ? t->ttl-seconds() : -1); struct peer * p = t->peers; while (p) { fprintf(s, "\t"); @@ -559,8 +559,8 @@ void dht_print (FILE * s, const struct dht * d) { char buf[41]; buf[40] = '\0'; bin2hex(buf, d->id, 20); - char secret[17*2]; - secret[17*2+1] = '\0'; + char secret[16*2+1]; + secret[16*2] = '\0'; bin2hex(secret, d->secret, 16); fprintf(s, "id=%s socket=%d t=%u p=%u tmax=%u pmax=%u p/t-max=%u runsec=%ld rxp=%u txp=%u rxb=%u txb=%u secret=%s tt=%u tr=%u p=%u\n", buf, d->socket, d->torrents_num, d->peers_num, d->torrents_max, d->peers_max, d->peers_per_torrent_max, seconds()-d->time, d->rxp, d->txp, d->rxb, d->txb, secret, d->tt, d->tr, d->p); fprintf(s, "**** NODES ****\n"); @@ -587,12 +587,15 @@ void dht_print (FILE * s, const struct dht * d) { fprintf(s, "\t**** COUNT OF %s BUCKETS: %d\n", i ? "IPv6" : "IPv4", buckets); } fprintf(s, "**** COUNT OF NODES: %d\n", nodes); - printf("**** TORRENTS ****\n"); + fprintf(s, "**** TORRENTS ****\n"); struct torrent * t = d->torrents; + unsigned torrents = 0; while (t) { + torrents++; torrent_print(s, t); t = t->next; } + fprintf(s, "**** COUNT OF TORRENTS: %u\n", torrents); } /** @@ -2333,11 +2336,11 @@ void periodic (struct dht * d) { get_peers(d, &n->addr, t->hash); n = n->next; } - if (sent < K) { + if (sent < 1) { #define RTGP(buckets) {struct bucket * b = d->buckets; \ find(t->hash, &b, NULL); \ struct node * n = b->nodes; \ - while (sent < K && n) { \ + while (sent < 1 && n) { \ sent++; \ if (!n->unanswered) \ n->last_sent = seconds(); \ @@ -2348,11 +2351,11 @@ void periodic (struct dht * d) { RTGP(buckets); RTGP(buckets6); } - if (sent < K) { + if (sent < 1) { struct bucket * b = d->buckets; - while (sent < K && b) { + while (sent < 1 && b) { n = b->nodes; - while (sent < K && n) { + while (sent < 1 && n) { sent++; if (!n->unanswered) n->last_sent = seconds(); @@ -2423,7 +2426,11 @@ void periodic (struct dht * d) { t = t->next; } L(debug, d, "txqp=%u rxrp=%u rxqp=%u txrp=%u", d->txqp, d->rxrp, d->rxqp, d->txrp); - assert(!(d->txqp > 16384 || d->rxrp > 16384 || d->rxqp > 16384 || d->txrp > 16384)); +#define TOOMUCH 32727 + if (d->txqp > TOOMUCH || d->rxrp > TOOMUCH || d->rxqp > TOOMUCH || d->txrp > TOOMUCH) { + dht_print(stdout, d); + raise(SIGABRT); + } d->txqp = d->txrp = d->rxqp = d->rxrp = 0; } |