From 863553891b296c5574d6b0893ad21fe16b97a6ea Mon Sep 17 00:00:00 2001 From: Dimitri Staessens Date: Mon, 18 Dec 2023 13:22:37 +0100 Subject: irmd: Fix passing symmetric key on allocation The check if the flow requires a key in irmd flow_alloc was missing when setting the pointers for the piggyback data, so non-encrypted flow allocations failed on irm_msg__pack(). Signed-off-by: Dimitri Staessens Signed-off-by: Sander Vrijders --- src/irmd/main.c | 12 ++++++++---- src/lib/dev.c | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/irmd/main.c b/src/irmd/main.c index 59c1c5ec..4284b4c5 100644 --- a/src/irmd/main.c +++ b/src/irmd/main.c @@ -1507,6 +1507,8 @@ static int flow_accept(pid_t pid, if (f_out->qs.cypher_s > 0) { data->data = s; data->len = SYMMKEYSZ; + } else { + free(s); } log_info("Flow on flow_id %d allocated.", f->flow_id); @@ -1626,7 +1628,7 @@ static int flow_alloc(pid_t pid, uint8_t * hash; ssize_t key_len; void * pkp; /* my public key pair */ - buffer_t tmp; /* buffer for public key */ + buffer_t tmp = {NULL, 0}; /* buffer for public key */ uint8_t buf[MSGBUFSZ]; uint8_t * s = NULL; int err; @@ -1741,10 +1743,12 @@ static int flow_alloc(pid_t pid, pthread_rwlock_unlock(&irmd.reg_lock); free(hash); - crypt_dh_pkp_destroy(pkp); - data->data = s; - data->len = SYMMKEYSZ; + if (qs.cypher_s > 0) { + crypt_dh_pkp_destroy(pkp); + data->data = s; + data->len = SYMMKEYSZ; + } log_info("Flow on flow_id %d allocated.", flow_id); diff --git a/src/lib/dev.c b/src/lib/dev.c index acf18da2..74a8c62d 100644 --- a/src/lib/dev.c +++ b/src/lib/dev.c @@ -475,7 +475,7 @@ static int flow_init(int flow_id, flow->crypt.flags = qs.cypher_s; /* TODO: remove cypher_s from qos */ - if (flow->crypt.flags > 0) + if (flow->crypt.flags > 0 && s != NULL) /* static analyzer s != NULL */ memcpy(flow->crypt.key, s ,SYMMKEYSZ); else memset(flow->crypt.key, 0, SYMMKEYSZ); -- cgit v1.2.3