From 477973fd217114dec8218cb7f8d99655272a3669 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Thu, 10 Oct 2019 07:58:21 +0200 Subject: [PATCH] Check the return value of node_write_config() while handling invitations. --- src/meshlink.c | 2 +- src/meshlink_internal.h | 2 +- src/net_setup.c | 2 +- src/protocol_auth.c | 9 ++++++++- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/meshlink.c b/src/meshlink.c index 4162b36e..7a01bd0f 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -3535,7 +3535,7 @@ void handle_network_change(meshlink_handle_t *mesh, bool online) { retry(mesh); } -void call_error_cb(meshlink_handle_t *mesh) { +void call_error_cb(meshlink_handle_t *mesh, meshlink_errno_t meshlink_errno) { // We should only call the callback function if we are in the background thread. if(!mesh->error_cb) { return; diff --git a/src/meshlink_internal.h b/src/meshlink_internal.h index ba7f7d15..e7b184e4 100644 --- a/src/meshlink_internal.h +++ b/src/meshlink_internal.h @@ -258,7 +258,7 @@ extern meshlink_log_level_t global_log_level; extern meshlink_log_cb_t global_log_cb; extern void handle_duplicate_node(meshlink_handle_t *mesh, struct node_t *n); extern void handle_network_change(meshlink_handle_t *mesh, bool online); -extern void call_error_cb(meshlink_handle_t *mesh); +extern void call_error_cb(meshlink_handle_t *mesh, meshlink_errno_t meshlink_errno); /// Per-instance PRNG static inline int prng(meshlink_handle_t *mesh, uint64_t max) { diff --git a/src/net_setup.c b/src/net_setup.c index b4a16c7e..667d15a3 100644 --- a/src/net_setup.c +++ b/src/net_setup.c @@ -272,7 +272,7 @@ bool node_write_config(meshlink_handle_t *mesh, node_t *n) { config_t config = {buf, packmsg_output_size(&out, buf)}; if(!config_write(mesh, "current", n->name, &config, mesh->config_key)) { - call_error_cb(mesh); + call_error_cb(mesh, MESHLINK_ESTORAGE); return false; } diff --git a/src/protocol_auth.c b/src/protocol_auth.c index 12e81e4c..4026c41f 100644 --- a/src/protocol_auth.c +++ b/src/protocol_auth.c @@ -164,8 +164,15 @@ static bool finalize_invitation(meshlink_handle_t *mesh, connection_t *c, const n->devclass = DEV_CLASS_UNKNOWN; n->ecdsa = ecdsa_set_public_key(data); n->submesh = c->submesh; + + if(!node_write_config(mesh, n)) { + logger(mesh, MESHLINK_ERROR, "Error writing configuration file for invited node %s!\n", c->name); + free_node(n); + return false; + + } + node_add(mesh, n); - node_write_config(mesh, n); logger(mesh, MESHLINK_INFO, "Key successfully received from %s", c->name); -- 2.39.5