From: Guus Sliepen Date: Thu, 16 Apr 2020 00:08:38 +0000 (+0200) Subject: Ensure exported host files have a port in the canonical address. X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=fe7be9e345bcc652914ef6fc51302da13d4c9c8d;p=meshlink Ensure exported host files have a port in the canonical address. --- diff --git a/src/meshlink.c b/src/meshlink.c index 32d10447..b85795d4 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -2424,13 +2424,20 @@ bool meshlink_set_canonical_address(meshlink_handle_t *mesh, meshlink_node_t *no } if(!is_valid_hostname(address)) { - logger(mesh, MESHLINK_DEBUG, "Invalid character in address: %s\n", address); + logger(mesh, MESHLINK_DEBUG, "Invalid character in address: %s", address); + meshlink_errno = MESHLINK_EINVAL; + return false; + } + + if((node_t *)node != mesh->self && !port) { + logger(mesh, MESHLINK_DEBUG, "Missing port number!"); meshlink_errno = MESHLINK_EINVAL; return false; + } if(port && !is_valid_port(port)) { - logger(mesh, MESHLINK_DEBUG, "Invalid character in port: %s\n", address); + logger(mesh, MESHLINK_DEBUG, "Invalid character in port: %s", address); meshlink_errno = MESHLINK_EINVAL; return false; } @@ -3042,7 +3049,15 @@ char *meshlink_export(meshlink_handle_t *mesh) { packmsg_add_int32(&out, mesh->self->devclass); packmsg_add_bool(&out, mesh->self->status.blacklisted); packmsg_add_bin(&out, ecdsa_get_public_key(mesh->private_key), 32); - packmsg_add_str(&out, mesh->self->canonical_address ? mesh->self->canonical_address : ""); + + if(mesh->self->canonical_address && !strchr(mesh->self->canonical_address, ' ')) { + char *canonical_address = NULL; + xasprintf(&canonical_address, "%s %s", mesh->self->canonical_address, mesh->myport); + packmsg_add_str(&out, canonical_address); + free(canonical_address); + } else { + packmsg_add_str(&out, mesh->self->canonical_address ? mesh->self->canonical_address : ""); + } uint32_t count = 0; diff --git a/src/net_socket.c b/src/net_socket.c index 8b293d5d..51a79c1d 100644 --- a/src/net_socket.c +++ b/src/net_socket.c @@ -283,12 +283,14 @@ static bool get_next_outgoing_address(meshlink_handle_t *mesh, outgoing_t *outgo if(port) { *port++ = 0; port = xstrdup(port); + adns_queue(mesh, address, port, canonical_resolve_cb, outgoing->node, 2); + return false; } else { - port = xstrdup(mesh->myport); + logger(mesh, MESHLINK_ERROR, "Canonical address for %s is missing port number", n->name); + free(address); + outgoing->state = OUTGOING_RECENT; } - adns_queue(mesh, address, port, canonical_resolve_cb, outgoing->node, 2); - return false; } else { outgoing->state = OUTGOING_RECENT; }