]> git.meshlink.io Git - meshlink/commitdiff
Fix segfault when two nodes that just joined a mesh want to autoconnect to each other.
authorGuus Sliepen <guus@meshlink.io>
Tue, 12 Aug 2014 20:03:32 +0000 (22:03 +0200)
committerGuus Sliepen <guus@meshlink.io>
Tue, 12 Aug 2014 20:03:32 +0000 (22:03 +0200)
In this case, we have not exchanged public keys yet. That should not be
a problem, but we blindly pass a NULL pointer to sptps_start() in this
case which blindly dereferences it. Fix sptps_start() by making sure no
arguments are NULL, and teach MeshLink to exchange keys between
reachable nodes when it tries to make a meta-connection.

src/protocol_auth.c
src/sptps.c

index d359b9b638c9aae8e9699201317bc5d470bb285f..9cb96b6590aecd6dd47f1af1fb23fc2ca694178c 100644 (file)
@@ -329,11 +329,20 @@ bool id_h(meshlink_handle_t *mesh, connection_t *c, const char *request) {
                        logger(mesh, MESHLINK_ERROR, "Peer %s had unknown identity (%s)", c->hostname, c->name);
                        return false;
                }
+       }
 
-               read_ecdsa_public_key(mesh, c);
-       } else {
-               if(c->protocol_minor && !ecdsa_active(c->ecdsa))
-                       c->protocol_minor = 1;
+       read_ecdsa_public_key(mesh, c);
+
+       if(!ecdsa_active(c->ecdsa)) {
+               logger(mesh, MESHLINK_ERROR, "No key known for peer %s (%s)", c->name, c->hostname);
+
+               node_t *n = lookup_node(mesh, c->name);
+               if(n && !n->status.waitingforkey) {
+                       logger(mesh, MESHLINK_INFO, "Requesting key from peer %s (%s)", c->name, c->hostname);
+                       send_req_key(mesh, n);
+               }
+
+               return false;
        }
 
        /* Forbid version rollback for nodes whose ECDSA key we know */
index 49e0a336de6a66436fb245507bb16d0ea869ac94..2e9ac6fe63331917c320805fdac592fea91753f7 100644 (file)
@@ -565,6 +565,9 @@ bool sptps_receive_data(sptps_t *s, const void *data, size_t len) {
 
 // Start a SPTPS session.
 bool sptps_start(sptps_t *s, void *handle, bool initiator, bool datagram, ecdsa_t *mykey, ecdsa_t *hiskey, const char *label, size_t labellen, send_data_t send_data, receive_record_t receive_record) {
+       if(!s || !mykey || !hiskey || !label || !labellen || !send_data || !receive_record)
+               return error(s, EINVAL, "Invalid argument to sptps_start()");
+
        // Initialise struct sptps
        memset(s, 0, sizeof *s);