From 961c79637c3dcda57543e70d88b9c47c13ce3b07 Mon Sep 17 00:00:00 2001 From: Jakub Jelen Date: Thu, 24 Jul 2025 19:19:12 +0200 Subject: [PATCH] options: Fix possible memory leaks on error conditions when setting keys for bind Signed-off-by: Jakub Jelen Reviewed-by: Andreas Schneider --- src/options.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/options.c b/src/options.c index 5a1698d2..1f849b64 100644 --- a/src/options.c +++ b/src/options.c @@ -2285,6 +2285,9 @@ ssh_bind_options_set(ssh_bind sshbind, SSH_FATAL, "The host key size %d is too small.", ssh_key_size(key)); + if (type != SSH_BIND_OPTIONS_IMPORT_KEY) { + SSH_KEY_FREE(key); + } return -1; } key_type = ssh_key_type(key); @@ -2330,6 +2333,11 @@ ssh_bind_options_set(ssh_bind sshbind, ssh_key_free(key); return -1; } + } else if (type == SSH_BIND_OPTIONS_IMPORT_KEY_STR) { + if (bind_key_loc == NULL) { + ssh_key_free(key); + return -1; + } } else { if (bind_key_loc == NULL) { return -1;