summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2013-03-08 22:16:06 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2013-03-08 22:16:06 +0100
commitf4e89562564799fd508868c3d8d4ffb7bcf6a348 (patch)
tree051cd9abb81460248d3a8a301adec14b41fb10ea /src
parent103133c2fc7110085bbb730a71c762f6759e84e9 (diff)
downloadfastd-f4e89562564799fd508868c3d8d4ffb7bcf6a348.tar
fastd-f4e89562564799fd508868c3d8d4ffb7bcf6a348.zip
Fix crash on invalid key definitions
Diffstat (limited to 'src')
-rw-r--r--src/protocol_ec25519_fhmqvc.c49
1 files changed, 23 insertions, 26 deletions
diff --git a/src/protocol_ec25519_fhmqvc.c b/src/protocol_ec25519_fhmqvc.c
index 9b18ad5..d218e62 100644
--- a/src/protocol_ec25519_fhmqvc.c
+++ b/src/protocol_ec25519_fhmqvc.c
@@ -181,42 +181,39 @@ static size_t key_count(fastd_context_t *ctx, const ecc_int256_t *key) {
}
static void protocol_peer_configure(fastd_context_t *ctx, fastd_peer_config_t *peer_conf) {
- if (!peer_conf->protocol_config) {
- if (!peer_conf->key) {
- pr_warn(ctx, "no key configured for `%s', disabling peer", peer_conf->name);
- goto disable;
- }
-
- ecc_int256_t key;
- if (!read_key(key.p, peer_conf->key)) {
- pr_warn(ctx, "invalid key configured for `%s', disabling peer", peer_conf->name);
- goto disable;
- }
+ if (peer_conf->protocol_config)
+ return;
- peer_conf->protocol_config = malloc(sizeof(fastd_protocol_peer_config_t));
- peer_conf->protocol_config->public_key = key;
+ if (!peer_conf->key) {
+ pr_warn(ctx, "no key configured for `%s', disabling peer", peer_conf->name);
+ return;
+ }
- if (memcmp(peer_conf->protocol_config->public_key.p, ctx->conf->protocol_config->public_key.p, 32) == 0) {
- pr_debug(ctx, "found own key as `%s', ignoring peer", peer_conf->name);
- goto disable;
- }
+ ecc_int256_t key;
+ if (!read_key(key.p, peer_conf->key)) {
+ pr_warn(ctx, "invalid key configured for `%s', disabling peer", peer_conf->name);
+ return;
}
- return;
+ peer_conf->protocol_config = malloc(sizeof(fastd_protocol_peer_config_t));
+ peer_conf->protocol_config->public_key = key;
- disable:
- peer_conf->enabled = false;
+ if (memcmp(peer_conf->protocol_config->public_key.p, ctx->conf->protocol_config->public_key.p, 32) == 0)
+ pr_debug(ctx, "found own key as `%s', ignoring peer", peer_conf->name);
}
static bool protocol_peer_check(fastd_context_t *ctx, fastd_peer_config_t *peer_conf) {
- if (memcmp(peer_conf->protocol_config->public_key.p, ctx->conf->protocol_config->public_key.p, 32) == 0) {
+ if (!peer_conf->protocol_config)
return false;
- }
+
+ if (memcmp(peer_conf->protocol_config->public_key.p, ctx->conf->protocol_config->public_key.p, 32) == 0)
+ return false;
+
if (key_count(ctx, &peer_conf->protocol_config->public_key) > 1) {
- char buf[65];
- hexdump(buf, peer_conf->protocol_config->public_key.p);
- pr_warn(ctx, "more than one peer is configured with key %s, disabling %s", buf, peer_conf->name);
- return false;
+ char buf[65];
+ hexdump(buf, peer_conf->protocol_config->public_key.p);
+ pr_warn(ctx, "more than one peer is configured with key %s, disabling %s", buf, peer_conf->name);
+ return false;
}
return true;