Zerotierone: Infinite for(;;) loop in choosing the best relay

Created on 17 Jul 2016  路  4Comments  路  Source: zerotier/ZeroTierOne

node/Switch.cpp

        if (!viaPath) {
            if (network) {
                unsigned int bestq = ~((unsigned int)0); // max unsigned int since quality is lower==better
                unsigned int ptr = 0;
                for(;;) {
                    const Address raddr(network->config().nextRelay(ptr));
                    if (raddr) {
                        SharedPtr<Peer> rp(RR->topology->getPeer(raddr));
                        if (rp) {
                            const unsigned int q = rp->relayQuality(now);
                            if (q < bestq) {
                                bestq = q;
                                rp.swap(relay);
                            }
                        }
                    } else break;
                }
            }
$7 = 1
(gdb) i b
Num     Type           Disp Enb Address            What
1       breakpoint     keep y   0x00000000004818bb in ZeroTier::Switch::_trySend(ZeroTier::Packet const&, bool, unsigned long) at node/Switch.cpp:821
        breakpoint already hit 2 times
(gdb) c
Continuing.

Thread 2 "zerotier-one" hit Breakpoint 1, ZeroTier::Switch::_trySend (this=0x7fb1fd542010, packet=..., encrypt=true, nwid=9342632507306147841) at node/Switch.cpp:821
821                                                     SharedPtr<Peer> rp(RR->topology->getPeer(raddr));
(gdb) p ptr
$8 = 1
(gdb) n
822                                                     if (rp) {
(gdb) p rp
$9 = {_ptr = 0x1ad0b90}
(gdb) c
Continuing.

Thread 2 "zerotier-one" hit Breakpoint 1, ZeroTier::Switch::_trySend (this=0x7fb1fd542010, packet=..., encrypt=true, nwid=9342632507306147841) at node/Switch.cpp:821
821                                                     SharedPtr<Peer> rp(RR->topology->getPeer(raddr));
(gdb) n
822                                                     if (rp) {
(gdb) p ptr
$10 = 1
(gdb) p rp
$11 = {_ptr = 0x1ad0b90}
(gdb)
bug

Most helpful comment

馃樀 馃槩 馃槶 馃敨

All 4 comments

馃樀 馃槩 馃槶 馃敨

Actual bug is in NetworkConfig::nextRelay(). It should increment &ptr in all cases.

Stupid bug fixed in dev.

Fixed in 1.1.14

Was this page helpful?
0 / 5 - 0 ratings