]> git.meshlink.io Git - meshlink/blobdiff - src/net_packet.c
Fix potential NULL pointer dereference.
[meshlink] / src / net_packet.c
index 38200e5a1d9a31f05bfe6b63ef86634eb9079374..b32c78f7d467456166e9551ca211242a651361f7 100644 (file)
@@ -102,7 +102,7 @@ static void send_mtu_probe_handler(event_loop_t *loop, void *data) {
        }
 
        if(n->mtuprobes == 31) {
-               if(!n->minmtu && n->status.want_udp) {
+               if(!n->minmtu && n->status.want_udp && n->nexthop && n->nexthop->connection) {
                        /* Send a dummy ANS_KEY to try to update the reflexive UDP address */
                        send_request(mesh, n->nexthop->connection, NULL, "%d %s %s . -1 -1 -1 0", ANS_KEY, mesh->self->name, n->name);
                        n->status.want_udp = false;
@@ -188,7 +188,13 @@ static void mtu_probe_h(meshlink_handle_t *mesh, node_t *n, vpn_packet_t *packet
                if(!n->status.udp_confirmed) {
                        char *address, *port;
                        sockaddr2str(&n->address, &address, &port);
-                       send_request(mesh, n->nexthop->connection, NULL, "%d %s %s . -1 -1 -1 0 %s %s", ANS_KEY, n->name, n->name, address, port);
+
+                       if(n->nexthop && n->nexthop->connection) {
+                               send_request(mesh, n->nexthop->connection, NULL, "%d %s %s . -1 -1 -1 0 %s %s", ANS_KEY, n->name, n->name, address, port);
+                       } else {
+                               logger(mesh, MESHLINK_WARNING, "Cannot send reflexive address to %s via %s", n->name, n->nexthop ? n->nexthop->name : n->name);
+                       }
+
                        free(address);
                        free(port);
                        n->status.udp_confirmed = true;
@@ -400,6 +406,11 @@ bool send_sptps_data(void *handle, uint8_t type, const void *data, size_t len) {
                char buf[len * 4 / 3 + 5];
                b64encode(data, buf, len);
 
+               if(!to->nexthop || !to->nexthop->connection) {
+                       logger(mesh, MESHLINK_WARNING, "Unable to forward SPTPS packet to %s via %s", to->name, to->nexthop ? to->nexthop->name : to->name);
+                       return false;
+               }
+
                /* If no valid key is known yet, send the packets using ANS_KEY requests,
                   to ensure we get to learn the reflexive UDP address. */
                if(!to->status.validkey) {