X-Git-Url: http://git.meshlink.io/?p=meshlink;a=blobdiff_plain;f=src%2Fmeshlink.c;h=32d10447aa57f755fe5531c7f8596feb528336a2;hp=4e258c5633f1a1e7e2bf1f4982bea39cd81231f6;hb=6cf7d2367e8f9008762d7a571cfa11a8dd850087;hpb=fec95d1221c2d7e2059d6ba2fe244211ccee95ad diff --git a/src/meshlink.c b/src/meshlink.c index 4e258c56..32d10447 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -665,24 +665,28 @@ static bool finalize_join(join_state_t *state, const void *buf, uint16_t len) { } char *name = packmsg_get_str_dup(&in); - packmsg_skip_element(&in); /* submesh */ + char *submesh_name = packmsg_get_str_dup(&in); dev_class_t devclass = packmsg_get_int32(&in); uint32_t count = packmsg_get_array(&in); - if(!name) { - logger(mesh, MESHLINK_DEBUG, "No Name found in invitation!\n"); + if(!name || !check_id(name)) { + logger(mesh, MESHLINK_DEBUG, "No valid Name found in invitation!\n"); + free(name); + free(submesh_name); return false; } - if(!check_id(name)) { - logger(mesh, MESHLINK_DEBUG, "Invalid Name found in invitation: %s!\n", name); + if(!submesh_name || (strcmp(submesh_name, CORE_MESH) && !check_id(submesh_name))) { + logger(mesh, MESHLINK_DEBUG, "No valid Submesh found in invitation!\n"); free(name); + free(submesh_name); return false; } if(!count) { logger(mesh, MESHLINK_ERROR, "Incomplete invitation file!\n"); free(name); + free(submesh_name); return false; } @@ -690,6 +694,8 @@ static bool finalize_join(join_state_t *state, const void *buf, uint16_t len) { free(mesh->self->name); mesh->name = name; mesh->self->name = xstrdup(name); + mesh->self->submesh = strcmp(submesh_name, CORE_MESH) ? lookup_or_create_submesh(mesh, submesh_name) : NULL; + free(submesh_name); mesh->self->devclass = devclass == DEV_CLASS_UNKNOWN ? mesh->devclass : devclass; // Initialize configuration directory