diff --git a/backport-0001-CVE-2023-6004-torture_config-Allow-multiple-in-usern.patch b/backport-0001-CVE-2023-6004-torture_config-Allow-multiple-in-usern.patch deleted file mode 100644 index b08fc3328714145d8ac4f64cf3c4a3b6bb4bf3d9..0000000000000000000000000000000000000000 --- a/backport-0001-CVE-2023-6004-torture_config-Allow-multiple-in-usern.patch +++ /dev/null @@ -1,112 +0,0 @@ -From c2c56bacab00766d01671413321d564227aabf19 Mon Sep 17 00:00:00 2001 -From: Norbert Pocs -Date: Sun, 5 Nov 2023 13:12:47 +0100 -Subject: [PATCH 01/20] CVE-2023-6004: torture_config: Allow multiple '@' in - usernames - -Signed-off-by: Norbert Pocs -Reviewed-by: Andreas Schneider -Reviewed-by: Jakub Jelen ---- - tests/unittests/torture_config.c | 56 +++++++++++++++++--------------- - 1 file changed, 30 insertions(+), 26 deletions(-) - -diff --git a/tests/unittests/torture_config.c b/tests/unittests/torture_config.c -index 406f1985..b7c763af 100644 ---- a/tests/unittests/torture_config.c -+++ b/tests/unittests/torture_config.c -@@ -995,23 +995,22 @@ static void torture_config_proxyjump(void **state, - assert_string_equal(session->opts.ProxyCommand, - "ssh -W '[%h]:%p' 2620:52:0::fed"); - -- /* In this part, we try various other config files and strings. */ -- -- /* Try to create some invalid configurations */ -- /* Non-numeric port */ -- config = "Host bad-port\n" -- "\tProxyJump jumpbox:22bad22\n"; -+ /* Multiple @ is allowed in second jump */ -+ config = "Host allowed-hostname\n" -+ "\tProxyJump localhost,user@principal.com@jumpbox:22\n"; - if (file != NULL) { - torture_write_file(file, config); - } else { - string = config; - } - torture_reset_config(session); -- ssh_options_set(session, SSH_OPTIONS_HOST, "bad-port"); -- _parse_config(session, file, string, SSH_ERROR); -+ ssh_options_set(session, SSH_OPTIONS_HOST, "allowed-hostname"); -+ _parse_config(session, file, string, SSH_OK); -+ assert_string_equal(session->opts.ProxyCommand, -+ "ssh -J user@principal.com@jumpbox:22 -W '[%h]:%p' localhost"); - -- /* Too many @ */ -- config = "Host bad-hostname\n" -+ /* Multiple @ is allowed */ -+ config = "Host allowed-hostname\n" - "\tProxyJump user@principal.com@jumpbox:22\n"; - if (file != NULL) { - torture_write_file(file, config); -@@ -1019,7 +1018,24 @@ static void torture_config_proxyjump(void **state, - string = config; - } - torture_reset_config(session); -- ssh_options_set(session, SSH_OPTIONS_HOST, "bad-hostname"); -+ ssh_options_set(session, SSH_OPTIONS_HOST, "allowed-hostname"); -+ _parse_config(session, file, string, SSH_OK); -+ assert_string_equal(session->opts.ProxyCommand, -+ "ssh -l user@principal.com -p 22 -W '[%h]:%p' jumpbox"); -+ -+ /* In this part, we try various other config files and strings. */ -+ -+ /* Try to create some invalid configurations */ -+ /* Non-numeric port */ -+ config = "Host bad-port\n" -+ "\tProxyJump jumpbox:22bad22\n"; -+ if (file != NULL) { -+ torture_write_file(file, config); -+ } else { -+ string = config; -+ } -+ torture_reset_config(session); -+ ssh_options_set(session, SSH_OPTIONS_HOST, "bad-port"); - _parse_config(session, file, string, SSH_ERROR); - - /* Braces mismatch in hostname */ -@@ -1094,18 +1110,6 @@ static void torture_config_proxyjump(void **state, - ssh_options_set(session, SSH_OPTIONS_HOST, "bad-port-2"); - _parse_config(session, file, string, SSH_ERROR); - -- /* Too many @ in second jump */ -- config = "Host bad-hostname\n" -- "\tProxyJump localhost,user@principal.com@jumpbox:22\n"; -- if (file != NULL) { -- torture_write_file(file, config); -- } else { -- string = config; -- } -- torture_reset_config(session); -- ssh_options_set(session, SSH_OPTIONS_HOST, "bad-hostname"); -- _parse_config(session, file, string, SSH_ERROR); -- - /* Braces mismatch in second jump */ - config = "Host mismatch\n" - "\tProxyJump localhost,[::1:20\n"; -@@ -1448,10 +1452,10 @@ static void torture_config_parser_get_cmd(void **state) - } else if (pid == 0) { - ssh_execute_command(tok, fileno(outfile), fileno(outfile)); - /* Does not return */ -- } else { -- /* parent -+ } else { -+ /* parent - * wait child process */ -- wait(NULL); -+ wait(NULL); - infile = fopen("output.log", "r"); - assert_non_null(infile); - p = fgets(buffer, sizeof(buffer), infile); --- -2.33.0 - diff --git a/backport-0002-CVE-2023-6004-config_parser-Allow-multiple-in-userna.patch b/backport-0002-CVE-2023-6004-config_parser-Allow-multiple-in-userna.patch deleted file mode 100644 index 9dc7b28cdbbf5c9204f4ee25935af5569efe726c..0000000000000000000000000000000000000000 --- a/backport-0002-CVE-2023-6004-config_parser-Allow-multiple-in-userna.patch +++ /dev/null @@ -1,29 +0,0 @@ -From a66b4a6eae6614d200a3625862d77565b96a7cd3 Mon Sep 17 00:00:00 2001 -From: Norbert Pocs -Date: Wed, 1 Nov 2023 11:24:43 +0100 -Subject: [PATCH 02/20] CVE-2023-6004: config_parser: Allow multiple '@' in - usernames - -Signed-off-by: Norbert Pocs -Reviewed-by: Andreas Schneider -Reviewed-by: Jakub Jelen ---- - src/config_parser.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/src/config_parser.c b/src/config_parser.c -index 0d988fec..cf83e2c5 100644 ---- a/src/config_parser.c -+++ b/src/config_parser.c -@@ -180,7 +180,7 @@ int ssh_config_parse_uri(const char *tok, - } - - /* Username part (optional) */ -- endp = strchr(tok, '@'); -+ endp = strrchr(tok, '@'); - if (endp != NULL) { - /* Zero-length username is not valid */ - if (tok == endp) { --- -2.33.0 - diff --git a/backport-0003-CVE-2023-6004-options-Simplify-the-hostname-parsing-.patch b/backport-0003-CVE-2023-6004-options-Simplify-the-hostname-parsing-.patch deleted file mode 100644 index 68632313c533888c11f1ea81c1d5a55fdffc5db8..0000000000000000000000000000000000000000 --- a/backport-0003-CVE-2023-6004-options-Simplify-the-hostname-parsing-.patch +++ /dev/null @@ -1,80 +0,0 @@ -From 8615c24647f773a5e04203c7459512715d698be1 Mon Sep 17 00:00:00 2001 -From: Norbert Pocs -Date: Tue, 31 Oct 2023 09:48:52 +0100 -Subject: [PATCH 03/20] CVE-2023-6004: options: Simplify the hostname parsing - in ssh_options_set - -Using ssh_config_parse_uri can simplify the parsing of the host -parsing inside the function of ssh_options_set - -Signed-off-by: Norbert Pocs -Reviewed-by: Andreas Schneider -Reviewed-by: Jakub Jelen ---- - src/options.c | 40 ++++++++++++++++------------------------ - 1 file changed, 16 insertions(+), 24 deletions(-) - -diff --git a/src/options.c b/src/options.c -index 6f2c9397..38511455 100644 ---- a/src/options.c -+++ b/src/options.c -@@ -37,6 +37,7 @@ - #include "libssh/session.h" - #include "libssh/misc.h" - #include "libssh/options.h" -+#include "libssh/config_parser.h" - #ifdef WITH_SERVER - #include "libssh/server.h" - #include "libssh/bind.h" -@@ -515,33 +516,24 @@ int ssh_options_set(ssh_session session, enum ssh_options_e type, - ssh_set_error_invalid(session); - return -1; - } else { -- q = strdup(value); -- if (q == NULL) { -- ssh_set_error_oom(session); -+ char *username = NULL, *hostname = NULL, *port = NULL; -+ rc = ssh_config_parse_uri(value, &username, &hostname, &port); -+ if (rc != SSH_OK) { - return -1; - } -- p = strrchr(q, '@'); -- -- SAFE_FREE(session->opts.host); -- -- if (p) { -- *p = '\0'; -- session->opts.host = strdup(p + 1); -- if (session->opts.host == NULL) { -- SAFE_FREE(q); -- ssh_set_error_oom(session); -- return -1; -- } -- -+ if (port != NULL) { -+ SAFE_FREE(username); -+ SAFE_FREE(hostname); -+ SAFE_FREE(port); -+ return -1; -+ } -+ if (username != NULL) { - SAFE_FREE(session->opts.username); -- session->opts.username = strdup(q); -- SAFE_FREE(q); -- if (session->opts.username == NULL) { -- ssh_set_error_oom(session); -- return -1; -- } -- } else { -- session->opts.host = q; -+ session->opts.username = username; -+ } -+ if (hostname != NULL) { -+ SAFE_FREE(session->opts.host); -+ session->opts.host = hostname; - } - } - break; --- -2.33.0 - diff --git a/backport-0004-CVE-2023-6004-misc-Add-function-to-check-allowed-cha.patch b/backport-0004-CVE-2023-6004-misc-Add-function-to-check-allowed-cha.patch deleted file mode 100644 index 296fbbabac922d54d3ce4e91daf4656594231725..0000000000000000000000000000000000000000 --- a/backport-0004-CVE-2023-6004-misc-Add-function-to-check-allowed-cha.patch +++ /dev/null @@ -1,118 +0,0 @@ -From c6180409677c765e6b9ae2b18a3a7a9671ac1dbe Mon Sep 17 00:00:00 2001 -From: Norbert Pocs -Date: Tue, 10 Oct 2023 12:44:16 +0200 -Subject: [PATCH 04/20] CVE-2023-6004: misc: Add function to check allowed - characters of a hostname - -The hostname can be a domain name or an ip address. The colon has to be -allowed because of IPv6 even it is prohibited in domain names. - -Signed-off-by: Norbert Pocs -Reviewed-by: Andreas Schneider -Reviewed-by: Jakub Jelen ---- - include/libssh/misc.h | 3 ++ - src/misc.c | 68 +++++++++++++++++++++++++++++++++++++++++++ - 2 files changed, 71 insertions(+) - -diff --git a/include/libssh/misc.h b/include/libssh/misc.h -index 924da533..0924ba7f 100644 ---- a/include/libssh/misc.h -+++ b/include/libssh/misc.h -@@ -103,6 +103,9 @@ int ssh_newline_vis(const char *string, char *buf, size_t buf_len); - int ssh_tmpname(char *name); - - char *ssh_strreplace(const char *src, const char *pattern, const char *repl); -+ -+int ssh_check_hostname_syntax(const char *hostname); -+ - #ifdef __cplusplus - } - #endif -diff --git a/src/misc.c b/src/misc.c -index 7c478a77..be6ee836 100644 ---- a/src/misc.c -+++ b/src/misc.c -@@ -94,6 +94,8 @@ - #define ZLIB_STRING "" - #endif - -+#define ARPA_DOMAIN_MAX_LEN 63 -+ - /** - * @defgroup libssh_misc The SSH helper functions - * @ingroup libssh -@@ -1974,4 +1976,70 @@ char *ssh_strerror(int err_num, char *buf, size_t buflen) - #endif /* defined(__linux__) && defined(__GLIBC__) && defined(_GNU_SOURCE) */ - } - -+/** -+ * @brief Checks syntax of a domain name -+ * -+ * The check is made based on the RFC1035 section 2.3.1 -+ * Allowed characters are: hyphen, period, digits (0-9) and letters (a-zA-Z) -+ * -+ * The label should be no longer than 63 characters -+ * The label should start with a letter and end with a letter or number -+ * The label in this implementation can start with a number to allow virtual -+ * URLs to pass. Note that this will make IPv4 addresses to pass -+ * this check too. -+ * -+ * @param hostname The domain name to be checked, has to be null terminated -+ * -+ * @return SSH_OK if the hostname passes syntax check -+ * SSH_ERROR otherwise or if hostname is NULL or empty string -+ */ -+int ssh_check_hostname_syntax(const char *hostname) -+{ -+ char *it = NULL, *s = NULL, *buf = NULL; -+ size_t it_len; -+ char c; -+ -+ if (hostname == NULL || strlen(hostname) == 0) { -+ return SSH_ERROR; -+ } -+ -+ /* strtok_r writes into the string, keep the input clean */ -+ s = strdup(hostname); -+ if (s == NULL) { -+ return SSH_ERROR; -+ } -+ -+ it = strtok_r(s, ".", &buf); -+ /* if the token has 0 length */ -+ if (it == NULL) { -+ free(s); -+ return SSH_ERROR; -+ } -+ do { -+ it_len = strlen(it); -+ if (it_len > ARPA_DOMAIN_MAX_LEN || -+ /* the first char must be a letter, but some virtual urls start -+ * with a number */ -+ isalnum(it[0]) == 0 || -+ isalnum(it[it_len - 1]) == 0) { -+ free(s); -+ return SSH_ERROR; -+ } -+ while (*it != '\0') { -+ c = *it; -+ /* the "." is allowed too, but tokenization removes it from the -+ * string */ -+ if (isalnum(c) == 0 && c != '-') { -+ free(s); -+ return SSH_ERROR; -+ } -+ it++; -+ } -+ } while ((it = strtok_r(NULL, ".", &buf)) != NULL); -+ -+ free(s); -+ -+ return SSH_OK; -+} -+ - /** @} */ --- -2.33.0 - diff --git a/backport-0005-CVE-2023-6004-torture_misc-Add-test-for-ssh_check_ho.patch b/backport-0005-CVE-2023-6004-torture_misc-Add-test-for-ssh_check_ho.patch deleted file mode 100644 index 7a786879b589dc5881e601ef4264393d939529eb..0000000000000000000000000000000000000000 --- a/backport-0005-CVE-2023-6004-torture_misc-Add-test-for-ssh_check_ho.patch +++ /dev/null @@ -1,107 +0,0 @@ -From 9bbb817c0c5434f03613d0783b2ef5f52235b901 Mon Sep 17 00:00:00 2001 -From: Norbert Pocs -Date: Tue, 10 Oct 2023 12:45:28 +0200 -Subject: [PATCH 05/20] CVE-2023-6004: torture_misc: Add test for - ssh_check_hostname_syntax - -Signed-off-by: Norbert Pocs -Reviewed-by: Andreas Schneider -Reviewed-by: Jakub Jelen ---- - tests/unittests/torture_misc.c | 73 ++++++++++++++++++++++++++++++++++ - 1 file changed, 73 insertions(+) - -diff --git a/tests/unittests/torture_misc.c b/tests/unittests/torture_misc.c -index 9e346ff8..e682b6d4 100644 ---- a/tests/unittests/torture_misc.c -+++ b/tests/unittests/torture_misc.c -@@ -760,6 +760,78 @@ static void torture_ssh_strerror(void **state) - assert_non_null(out); - } - -+static void torture_ssh_check_hostname_syntax(void **state) -+{ -+ int rc; -+ (void)state; -+ -+ rc = ssh_check_hostname_syntax("duckduckgo.com"); -+ assert_int_equal(rc, SSH_OK); -+ rc = ssh_check_hostname_syntax("www.libssh.org"); -+ assert_int_equal(rc, SSH_OK); -+ rc = ssh_check_hostname_syntax("Some-Thing.com"); -+ assert_int_equal(rc, SSH_OK); -+ rc = ssh_check_hostname_syntax("amazon.a23456789012345678901234567890123456789012345678901234567890123"); -+ assert_int_equal(rc, SSH_OK); -+ rc = ssh_check_hostname_syntax("amazon.a23456789012345678901234567890123456789012345678901234567890123.a23456789012345678901234567890123456789012345678901234567890123.ok"); -+ assert_int_equal(rc, SSH_OK); -+ rc = ssh_check_hostname_syntax("amazon.a23456789012345678901234567890123456789012345678901234567890123.a23456789012345678901234567890123456789012345678901234567890123.a23456789012345678901234567890123456789012345678901234567890123"); -+ assert_int_equal(rc, SSH_OK); -+ rc = ssh_check_hostname_syntax("lavabo-inter.innocentes-manus-meas"); -+ assert_int_equal(rc, SSH_OK); -+ rc = ssh_check_hostname_syntax("localhost"); -+ assert_int_equal(rc, SSH_OK); -+ rc = ssh_check_hostname_syntax("a"); -+ assert_int_equal(rc, SSH_OK); -+ rc = ssh_check_hostname_syntax("a-0.b-b"); -+ assert_int_equal(rc, SSH_OK); -+ rc = ssh_check_hostname_syntax("libssh."); -+ assert_int_equal(rc, SSH_OK); -+ -+ rc = ssh_check_hostname_syntax(NULL); -+ assert_int_equal(rc, SSH_ERROR); -+ rc = ssh_check_hostname_syntax(""); -+ assert_int_equal(rc, SSH_ERROR); -+ rc = ssh_check_hostname_syntax("/"); -+ assert_int_equal(rc, SSH_ERROR); -+ rc = ssh_check_hostname_syntax("@"); -+ assert_int_equal(rc, SSH_ERROR); -+ rc = ssh_check_hostname_syntax("["); -+ assert_int_equal(rc, SSH_ERROR); -+ rc = ssh_check_hostname_syntax("`"); -+ assert_int_equal(rc, SSH_ERROR); -+ rc = ssh_check_hostname_syntax("{"); -+ assert_int_equal(rc, SSH_ERROR); -+ rc = ssh_check_hostname_syntax("&"); -+ assert_int_equal(rc, SSH_ERROR); -+ rc = ssh_check_hostname_syntax("|"); -+ assert_int_equal(rc, SSH_ERROR); -+ rc = ssh_check_hostname_syntax("\""); -+ assert_int_equal(rc, SSH_ERROR); -+ rc = ssh_check_hostname_syntax("`"); -+ assert_int_equal(rc, SSH_ERROR); -+ rc = ssh_check_hostname_syntax(" "); -+ assert_int_equal(rc, SSH_ERROR); -+ rc = ssh_check_hostname_syntax("*the+giant&\"rooks\".c0m"); -+ assert_int_equal(rc, SSH_ERROR); -+ rc = ssh_check_hostname_syntax("!www.libssh.org"); -+ assert_int_equal(rc, SSH_ERROR); -+ rc = ssh_check_hostname_syntax("--.--"); -+ assert_int_equal(rc, SSH_ERROR); -+ rc = ssh_check_hostname_syntax("libssh.a234567890123456789012345678901234567890123456789012345678901234"); -+ assert_int_equal(rc, SSH_ERROR); -+ rc = ssh_check_hostname_syntax("libssh.a234567890123456789012345678901234567890123456789012345678901234.a234567890123456789012345678901234567890123456789012345678901234"); -+ assert_int_equal(rc, SSH_ERROR); -+ rc = ssh_check_hostname_syntax("libssh-"); -+ assert_int_equal(rc, SSH_ERROR); -+ rc = ssh_check_hostname_syntax("fe80::9656:d028:8652:66b6"); -+ assert_int_equal(rc, SSH_ERROR); -+ rc = ssh_check_hostname_syntax("."); -+ assert_int_equal(rc, SSH_ERROR); -+ rc = ssh_check_hostname_syntax(".."); -+ assert_int_equal(rc, SSH_ERROR); -+} -+ - int torture_run_tests(void) { - int rc; - struct CMUnitTest tests[] = { -@@ -784,6 +856,7 @@ int torture_run_tests(void) { - cmocka_unit_test(torture_ssh_quote_file_name), - cmocka_unit_test(torture_ssh_strreplace), - cmocka_unit_test(torture_ssh_strerror), -+ cmocka_unit_test(torture_ssh_check_hostname_syntax), - }; - - ssh_init(); --- -2.33.0 - diff --git a/backport-0006-CVE-2023-6004-config_parser-Check-for-valid-syntax-o.patch b/backport-0006-CVE-2023-6004-config_parser-Check-for-valid-syntax-o.patch deleted file mode 100644 index c7a3761151576b15b7c9d1ca510c016b74a2534b..0000000000000000000000000000000000000000 --- a/backport-0006-CVE-2023-6004-config_parser-Check-for-valid-syntax-o.patch +++ /dev/null @@ -1,63 +0,0 @@ -From 22492b69bba22b102342afc574800d354a08e405 Mon Sep 17 00:00:00 2001 -From: Norbert Pocs -Date: Tue, 10 Oct 2023 18:33:56 +0200 -Subject: [PATCH 06/20] CVE-2023-6004: config_parser: Check for valid syntax of - a hostname if it is a domain name - -This prevents code injection. -The domain name syntax checker is based on RFC1035. - -Signed-off-by: Norbert Pocs -Reviewed-by: Andreas Schneider -Reviewed-by: Jakub Jelen ---- - src/config_parser.c | 12 +++++++++++- - 1 file changed, 11 insertions(+), 1 deletion(-) - -diff --git a/src/config_parser.c b/src/config_parser.c -index cf83e2c5..b8b94611 100644 ---- a/src/config_parser.c -+++ b/src/config_parser.c -@@ -30,6 +30,7 @@ - - #include "libssh/config_parser.h" - #include "libssh/priv.h" -+#include "libssh/misc.h" - - /* Returns the original string after skipping the leading whitespace - * until finding LF. -@@ -47,7 +48,7 @@ char *ssh_config_get_cmd(char **str) - break; - } - } -- -+ - for (r = c; *c; c++) { - if (*c == '\n') { - *c = '\0'; -@@ -167,6 +168,7 @@ int ssh_config_parse_uri(const char *tok, - { - char *endp = NULL; - long port_n; -+ int rc; - - /* Sanitize inputs */ - if (username != NULL) { -@@ -224,6 +226,14 @@ int ssh_config_parse_uri(const char *tok, - if (*hostname == NULL) { - goto error; - } -+ /* if not an ip, check syntax */ -+ rc = ssh_is_ipaddr(*hostname); -+ if (rc == 0) { -+ rc = ssh_check_hostname_syntax(*hostname); -+ if (rc != SSH_OK) { -+ goto error; -+ } -+ } - } - /* Skip also the closing bracket */ - if (*endp == ']') { --- -2.33.0 - diff --git a/backport-0007-CVE-2023-6004-torture_proxycommand-Add-test-for-prox.patch b/backport-0007-CVE-2023-6004-torture_proxycommand-Add-test-for-prox.patch deleted file mode 100644 index 9763e9c18ecb9878548bd010be7bd15f040201d9..0000000000000000000000000000000000000000 --- a/backport-0007-CVE-2023-6004-torture_proxycommand-Add-test-for-prox.patch +++ /dev/null @@ -1,87 +0,0 @@ -From d7467498fd988949edde9c6384973250fd454a8b Mon Sep 17 00:00:00 2001 -From: Norbert Pocs -Date: Tue, 10 Oct 2023 10:28:47 +0200 -Subject: [PATCH 07/20] CVE-2023-6004: torture_proxycommand: Add test for - proxycommand injection - -Signed-off-by: Norbert Pocs -Reviewed-by: Andreas Schneider -Reviewed-by: Jakub Jelen ---- - tests/client/torture_proxycommand.c | 53 +++++++++++++++++++++++++++++ - 1 file changed, 53 insertions(+) - -diff --git a/tests/client/torture_proxycommand.c b/tests/client/torture_proxycommand.c -index 9b8019ca..1bad4ccc 100644 ---- a/tests/client/torture_proxycommand.c -+++ b/tests/client/torture_proxycommand.c -@@ -166,6 +166,56 @@ static void torture_options_set_proxycommand_ssh_stderr(void **state) - assert_int_equal(rc & O_RDWR, O_RDWR); - } - -+static void torture_options_proxycommand_injection(void **state) -+{ -+ struct torture_state *s = *state; -+ struct passwd *pwd = NULL; -+ const char *malicious_host = "`echo foo > mfile`"; -+ const char *command = "nc %h %p"; -+ char *current_dir = NULL; -+ char *malicious_file_path = NULL; -+ int mfp_len; -+ int verbosity = torture_libssh_verbosity(); -+ struct stat sb; -+ int rc; -+ -+ pwd = getpwnam("bob"); -+ assert_non_null(pwd); -+ -+ rc = setuid(pwd->pw_uid); -+ assert_return_code(rc, errno); -+ -+ s->ssh.session = ssh_new(); -+ assert_non_null(s->ssh.session); -+ -+ ssh_options_set(s->ssh.session, SSH_OPTIONS_LOG_VERBOSITY, &verbosity); -+ // if we would be checking the rc, this should fail -+ ssh_options_set(s->ssh.session, SSH_OPTIONS_HOST, malicious_host); -+ -+ ssh_options_set(s->ssh.session, SSH_OPTIONS_USER, TORTURE_SSH_USER_ALICE); -+ -+ rc = ssh_options_set(s->ssh.session, SSH_OPTIONS_PROXYCOMMAND, command); -+ assert_int_equal(rc, 0); -+ rc = ssh_connect(s->ssh.session); -+ assert_ssh_return_code_equal(s->ssh.session, rc, SSH_ERROR); -+ -+ current_dir = torture_get_current_working_dir(); -+ assert_non_null(current_dir); -+ mfp_len = strlen(current_dir) + 6; -+ malicious_file_path = malloc(mfp_len); -+ assert_non_null(malicious_file_path); -+ rc = snprintf(malicious_file_path, mfp_len, -+ "%s/mfile", current_dir); -+ assert_int_equal(rc, mfp_len); -+ free(current_dir); -+ rc = stat(malicious_file_path, &sb); -+ assert_int_not_equal(rc, 0); -+ -+ // cleanup -+ remove(malicious_file_path); -+ free(malicious_file_path); -+} -+ - int torture_run_tests(void) { - int rc; - struct CMUnitTest tests[] = { -@@ -181,6 +231,9 @@ int torture_run_tests(void) { - cmocka_unit_test_setup_teardown(torture_options_set_proxycommand_ssh_stderr, - session_setup, - session_teardown), -+ cmocka_unit_test_setup_teardown(torture_options_proxycommand_injection, -+ NULL, -+ session_teardown), - }; - - --- -2.33.0 - diff --git a/backport-0008-CVE-2023-6004-torture_misc-Add-test-for-ssh_is_ipadd.patch b/backport-0008-CVE-2023-6004-torture_misc-Add-test-for-ssh_is_ipadd.patch deleted file mode 100644 index 6d34f5c17370991a0be6c01aee0dad1f1f2a79bf..0000000000000000000000000000000000000000 --- a/backport-0008-CVE-2023-6004-torture_misc-Add-test-for-ssh_is_ipadd.patch +++ /dev/null @@ -1,59 +0,0 @@ -From 62d3101c1f76b6891b70c50154e0e934d6b8cb57 Mon Sep 17 00:00:00 2001 -From: Norbert Pocs -Date: Mon, 6 Nov 2023 20:11:38 +0100 -Subject: [PATCH 08/20] CVE-2023-6004: torture_misc: Add test for ssh_is_ipaddr - -Signed-off-by: Norbert Pocs -Reviewed-by: Andreas Schneider -Reviewed-by: Jakub Jelen ---- - tests/unittests/torture_misc.c | 26 ++++++++++++++++++++++++++ - 1 file changed, 26 insertions(+) - -diff --git a/tests/unittests/torture_misc.c b/tests/unittests/torture_misc.c -index e682b6d4..b07392ab 100644 ---- a/tests/unittests/torture_misc.c -+++ b/tests/unittests/torture_misc.c -@@ -832,6 +832,31 @@ static void torture_ssh_check_hostname_syntax(void **state) - assert_int_equal(rc, SSH_ERROR); - } - -+static void torture_ssh_is_ipaddr(void **state) { -+ int rc; -+ (void)state; -+ -+ rc = ssh_is_ipaddr("201.255.3.69"); -+ assert_int_equal(rc, 1); -+ rc = ssh_is_ipaddr("::1"); -+ assert_int_equal(rc, 1); -+ rc = ssh_is_ipaddr("2001:0db8:85a3:0000:0000:8a2e:0370:7334"); -+ assert_int_equal(rc, 1); -+ -+ rc = ssh_is_ipaddr(".."); -+ assert_int_equal(rc, 0); -+ rc = ssh_is_ipaddr(":::"); -+ assert_int_equal(rc, 0); -+ rc = ssh_is_ipaddr("1.1.1.1.1"); -+ assert_int_equal(rc, 0); -+ rc = ssh_is_ipaddr("1.1"); -+ assert_int_equal(rc, 0); -+ rc = ssh_is_ipaddr("caesar"); -+ assert_int_equal(rc, 0); -+ rc = ssh_is_ipaddr("::xa:1"); -+ assert_int_equal(rc, 0); -+} -+ - int torture_run_tests(void) { - int rc; - struct CMUnitTest tests[] = { -@@ -857,6 +882,7 @@ int torture_run_tests(void) { - cmocka_unit_test(torture_ssh_strreplace), - cmocka_unit_test(torture_ssh_strerror), - cmocka_unit_test(torture_ssh_check_hostname_syntax), -+ cmocka_unit_test(torture_ssh_is_ipaddr), - }; - - ssh_init(); --- -2.33.0 - diff --git a/backport-0009-CVE-2023-6004-misc-Add-ipv6-link-local-check-for-an-.patch b/backport-0009-CVE-2023-6004-misc-Add-ipv6-link-local-check-for-an-.patch deleted file mode 100644 index c4f7858adb68da16567d5170cdcd60f77a65e844..0000000000000000000000000000000000000000 --- a/backport-0009-CVE-2023-6004-misc-Add-ipv6-link-local-check-for-an-.patch +++ /dev/null @@ -1,140 +0,0 @@ -From cea841d71c025f9c998b7d5fc9f2a2839df62921 Mon Sep 17 00:00:00 2001 -From: Norbert Pocs -Date: Tue, 28 Nov 2023 15:26:45 +0100 -Subject: [PATCH 09/20] CVE-2023-6004 misc: Add ipv6 link-local check for an ip - address - -Signed-off-by: Norbert Pocs -Reviewed-by: Andreas Schneider -Reviewed-by: Jakub Jelen ---- - src/CMakeLists.txt | 1 + - src/connect.c | 2 +- - src/misc.c | 44 ++++++++++++++++++++++++++++++++++++++------ - 3 files changed, 40 insertions(+), 7 deletions(-) - -diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt -index d6245c0d..807313b5 100644 ---- a/src/CMakeLists.txt -+++ b/src/CMakeLists.txt -@@ -91,6 +91,7 @@ endif() - if (WIN32) - set(LIBSSH_LINK_LIBRARIES - ${LIBSSH_LINK_LIBRARIES} -+ iphlpapi - ws2_32 - ) - endif (WIN32) -diff --git a/src/connect.c b/src/connect.c -index 57e37e63..15cae644 100644 ---- a/src/connect.c -+++ b/src/connect.c -@@ -136,7 +136,7 @@ static int getai(const char *host, int port, struct addrinfo **ai) - #endif - } - -- if (ssh_is_ipaddr(host)) { -+ if (ssh_is_ipaddr(host) == 1) { - /* this is an IP address */ - SSH_LOG(SSH_LOG_PACKET, "host %s matches an IP address", host); - hints.ai_flags |= AI_NUMERICHOST; -diff --git a/src/misc.c b/src/misc.c -index be6ee836..7081f12a 100644 ---- a/src/misc.c -+++ b/src/misc.c -@@ -32,6 +32,7 @@ - #include - #include - #include -+#include - - #endif /* _WIN32 */ - -@@ -59,6 +60,7 @@ - #include - #include - #include -+#include - - #ifdef HAVE_IO_H - #include -@@ -222,22 +224,37 @@ int ssh_is_ipaddr_v4(const char *str) - int ssh_is_ipaddr(const char *str) - { - int rc = SOCKET_ERROR; -+ char *s = strdup(str); - -- if (strchr(str, ':')) { -+ if (s == NULL) { -+ return -1; -+ } -+ if (strchr(s, ':')) { - struct sockaddr_storage ss; - int sslen = sizeof(ss); -+ char *network_interface = strchr(s, '%'); - -- /* TODO link-local (IP:v6:addr%ifname). */ -- rc = WSAStringToAddressA((LPSTR) str, -+ /* link-local (IP:v6:addr%ifname). */ -+ if (network_interface != NULL) { -+ rc = if_nametoindex(network_interface + 1); -+ if (rc == 0) { -+ free(s); -+ return 0; -+ } -+ *network_interface = '\0'; -+ } -+ rc = WSAStringToAddressA((LPSTR) s, - AF_INET6, - NULL, - (struct sockaddr*)&ss, - &sslen); - if (rc == 0) { -+ free(s); - return 1; - } - } - -+ free(s); - return ssh_is_ipaddr_v4(str); - } - #else /* _WIN32 */ -@@ -343,17 +360,32 @@ int ssh_is_ipaddr_v4(const char *str) - int ssh_is_ipaddr(const char *str) - { - int rc = -1; -+ char *s = strdup(str); - -- if (strchr(str, ':')) { -+ if (s == NULL) { -+ return -1; -+ } -+ if (strchr(s, ':')) { - struct in6_addr dest6; -+ char *network_interface = strchr(s, '%'); - -- /* TODO link-local (IP:v6:addr%ifname). */ -- rc = inet_pton(AF_INET6, str, &dest6); -+ /* link-local (IP:v6:addr%ifname). */ -+ if (network_interface != NULL) { -+ rc = if_nametoindex(network_interface + 1); -+ if (rc == 0) { -+ free(s); -+ return 0; -+ } -+ *network_interface = '\0'; -+ } -+ rc = inet_pton(AF_INET6, s, &dest6); - if (rc > 0) { -+ free(s); - return 1; - } - } - -+ free(s); - return ssh_is_ipaddr_v4(str); - } - --- -2.33.0 - diff --git a/backport-0010-CVE-2023-6004-torture_misc-Add-tests-for-ipv6-link-l.patch b/backport-0010-CVE-2023-6004-torture_misc-Add-tests-for-ipv6-link-l.patch deleted file mode 100644 index 2edfd436213ac48052ad44528c5cfabdd8100eb5..0000000000000000000000000000000000000000 --- a/backport-0010-CVE-2023-6004-torture_misc-Add-tests-for-ipv6-link-l.patch +++ /dev/null @@ -1,63 +0,0 @@ -From 2c492ee179d5caa2718c5e768bab6e0b2b64a8b0 Mon Sep 17 00:00:00 2001 -From: Norbert Pocs -Date: Tue, 28 Nov 2023 15:27:31 +0100 -Subject: [PATCH 10/20] CVE-2023-6004: torture_misc: Add tests for ipv6 - link-local - -Signed-off-by: Norbert Pocs -Reviewed-by: Andreas Schneider -Reviewed-by: Jakub Jelen ---- - tests/unittests/torture_misc.c | 20 ++++++++++++++++++++ - 1 file changed, 20 insertions(+) - -diff --git a/tests/unittests/torture_misc.c b/tests/unittests/torture_misc.c -index b07392ab..77166759 100644 ---- a/tests/unittests/torture_misc.c -+++ b/tests/unittests/torture_misc.c -@@ -17,7 +17,14 @@ - #include "torture.h" - #include "error.c" - -+#ifdef _WIN32 -+#include -+#else -+#include -+#endif -+ - #define TORTURE_TEST_DIR "/usr/local/bin/truc/much/.." -+#define TORTURE_IPV6_LOCAL_LINK "fe80::98e1:82ff:fe8d:28b3%%%s" - - const char template[] = "temp_dir_XXXXXX"; - -@@ -834,14 +841,27 @@ static void torture_ssh_check_hostname_syntax(void **state) - - static void torture_ssh_is_ipaddr(void **state) { - int rc; -+ char *interf = malloc(64); -+ char *test_interf = malloc(128); - (void)state; - -+ assert_non_null(interf); -+ assert_non_null(test_interf); - rc = ssh_is_ipaddr("201.255.3.69"); - assert_int_equal(rc, 1); - rc = ssh_is_ipaddr("::1"); - assert_int_equal(rc, 1); - rc = ssh_is_ipaddr("2001:0db8:85a3:0000:0000:8a2e:0370:7334"); - assert_int_equal(rc, 1); -+ if_indextoname(1, interf); -+ assert_non_null(interf); -+ rc = sprintf(test_interf, TORTURE_IPV6_LOCAL_LINK, interf); -+ /* the "%%s" is not written */ -+ assert_int_equal(rc, strlen(interf) + strlen(TORTURE_IPV6_LOCAL_LINK) - 3); -+ rc = ssh_is_ipaddr(test_interf); -+ assert_int_equal(rc, 1); -+ free(interf); -+ free(test_interf); - - rc = ssh_is_ipaddr(".."); - assert_int_equal(rc, 0); --- -2.33.0 - diff --git a/backport-0011-CVE-2023-48795-client-side-mitigation.patch b/backport-0011-CVE-2023-48795-client-side-mitigation.patch deleted file mode 100644 index 85d22e64c7ee664b3e4bf8c08e530ccc6b74cb67..0000000000000000000000000000000000000000 --- a/backport-0011-CVE-2023-48795-client-side-mitigation.patch +++ /dev/null @@ -1,450 +0,0 @@ -From 4cef5e965a46e9271aed62631b152e4bd23c1e3c Mon Sep 17 00:00:00 2001 -From: Aris Adamantiadis -Date: Tue, 12 Dec 2023 23:09:57 +0100 -Subject: [PATCH 11/20] CVE-2023-48795: client side mitigation - -Signed-off-by: Aris Adamantiadis -Signed-off-by: Jakub Jelen -Reviewed-by: Andreas Schneider ---- - include/libssh/packet.h | 1 + - include/libssh/session.h | 6 +++++ - src/curve25519.c | 19 +++---------- - src/dh-gex.c | 7 +---- - src/dh.c | 17 +++--------- - src/ecdh.c | 8 +----- - src/ecdh_crypto.c | 12 +++------ - src/ecdh_gcrypt.c | 10 +++---- - src/ecdh_mbedcrypto.c | 11 +++----- - src/kex.c | 34 +++++++++++++++++++---- - src/packet.c | 58 ++++++++++++++++++++++++++++++++++++++++ - src/packet_cb.c | 12 +++++++++ - 12 files changed, 126 insertions(+), 69 deletions(-) - -diff --git a/include/libssh/packet.h b/include/libssh/packet.h -index 7f10a709..f0c8cb20 100644 ---- a/include/libssh/packet.h -+++ b/include/libssh/packet.h -@@ -67,6 +67,7 @@ SSH_PACKET_CALLBACK(ssh_packet_ext_info); - SSH_PACKET_CALLBACK(ssh_packet_kexdh_init); - #endif - -+int ssh_packet_send_newkeys(ssh_session session); - int ssh_packet_send_unimplemented(ssh_session session, uint32_t seqnum); - int ssh_packet_parse_type(ssh_session session); - //int packet_flush(ssh_session session, int enforce_blocking); -diff --git a/include/libssh/session.h b/include/libssh/session.h -index eb14e97a..97936195 100644 ---- a/include/libssh/session.h -+++ b/include/libssh/session.h -@@ -81,6 +81,12 @@ enum ssh_pending_call_e { - * sending it twice during key exchange to simplify the state machine. */ - #define SSH_SESSION_FLAG_KEXINIT_SENT 4 - -+/* The current SSH2 session implements the "strict KEX" feature and should behave -+ * differently on SSH2_MSG_NEWKEYS. */ -+#define SSH_SESSION_FLAG_KEX_STRICT 0x0010 -+/* Unexpected packets have been sent while the session was still unencrypted */ -+#define SSH_SESSION_FLAG_KEX_TAINTED 0x0020 -+ - /* codes to use with ssh_handle_packets*() */ - /* Infinite timeout */ - #define SSH_TIMEOUT_INFINITE -1 -diff --git a/src/curve25519.c b/src/curve25519.c -index 66291b5f..4aeb4756 100644 ---- a/src/curve25519.c -+++ b/src/curve25519.c -@@ -335,16 +335,10 @@ static SSH_PACKET_CALLBACK(ssh_packet_client_curve25519_reply){ - } - - /* Send the MSG_NEWKEYS */ -- if (ssh_buffer_add_u8(session->out_buffer, SSH2_MSG_NEWKEYS) < 0) { -- goto error; -- } -- -- rc=ssh_packet_send(session); -+ rc = ssh_packet_send_newkeys(session); - if (rc == SSH_ERROR) { - goto error; - } -- -- SSH_LOG(SSH_LOG_PROTOCOL, "SSH_MSG_NEWKEYS sent"); - session->dh_handshake_state = DH_STATE_NEWKEYS_SENT; - - return SSH_PACKET_USED; -@@ -502,18 +496,13 @@ static SSH_PACKET_CALLBACK(ssh_packet_server_curve25519_init){ - return SSH_ERROR; - } - -- /* Send the MSG_NEWKEYS */ -- rc = ssh_buffer_add_u8(session->out_buffer, SSH2_MSG_NEWKEYS); -- if (rc < 0) { -- goto error; -- } -- - session->dh_handshake_state = DH_STATE_NEWKEYS_SENT; -- rc = ssh_packet_send(session); -+ -+ /* Send the MSG_NEWKEYS */ -+ rc = ssh_packet_send_newkeys(session); - if (rc == SSH_ERROR) { - goto error; - } -- SSH_LOG(SSH_LOG_PROTOCOL, "SSH_MSG_NEWKEYS sent"); - - return SSH_PACKET_USED; - error: -diff --git a/src/dh-gex.c b/src/dh-gex.c -index 91617081..642a88ae 100644 ---- a/src/dh-gex.c -+++ b/src/dh-gex.c -@@ -297,15 +297,10 @@ static SSH_PACKET_CALLBACK(ssh_packet_client_dhgex_reply) - } - - /* Send the MSG_NEWKEYS */ -- if (ssh_buffer_add_u8(session->out_buffer, SSH2_MSG_NEWKEYS) < 0) { -- goto error; -- } -- -- rc = ssh_packet_send(session); -+ rc = ssh_packet_send_newkeys(session); - if (rc == SSH_ERROR) { - goto error; - } -- SSH_LOG(SSH_LOG_PROTOCOL, "SSH_MSG_NEWKEYS sent"); - session->dh_handshake_state = DH_STATE_NEWKEYS_SENT; - - return SSH_PACKET_USED; -diff --git a/src/dh.c b/src/dh.c -index 011d97b3..e19e43d1 100644 ---- a/src/dh.c -+++ b/src/dh.c -@@ -398,16 +398,10 @@ SSH_PACKET_CALLBACK(ssh_packet_client_dh_reply){ - } - - /* Send the MSG_NEWKEYS */ -- if (ssh_buffer_add_u8(session->out_buffer, SSH2_MSG_NEWKEYS) < 0) { -- goto error; -- } -- -- rc=ssh_packet_send(session); -+ rc = ssh_packet_send_newkeys(session); - if (rc == SSH_ERROR) { - goto error; - } -- -- SSH_LOG(SSH_LOG_PROTOCOL, "SSH_MSG_NEWKEYS sent"); - session->dh_handshake_state = DH_STATE_NEWKEYS_SENT; - return SSH_PACKET_USED; - error: -@@ -551,15 +545,12 @@ int ssh_server_dh_process_init(ssh_session session, ssh_buffer packet) - } - SSH_LOG(SSH_LOG_DEBUG, "Sent KEX_DH_[GEX]_REPLY"); - -- if (ssh_buffer_add_u8(session->out_buffer, SSH2_MSG_NEWKEYS) < 0) { -- ssh_buffer_reinit(session->out_buffer); -- goto error; -- } - session->dh_handshake_state=DH_STATE_NEWKEYS_SENT; -- if (ssh_packet_send(session) == SSH_ERROR) { -+ /* Send the MSG_NEWKEYS */ -+ rc = ssh_packet_send_newkeys(session); -+ if (rc == SSH_ERROR) { - goto error; - } -- SSH_LOG(SSH_LOG_PACKET, "SSH_MSG_NEWKEYS sent"); - - return SSH_OK; - error: -diff --git a/src/ecdh.c b/src/ecdh.c -index e5b11ba9..af80beec 100644 ---- a/src/ecdh.c -+++ b/src/ecdh.c -@@ -93,16 +93,10 @@ SSH_PACKET_CALLBACK(ssh_packet_client_ecdh_reply){ - } - - /* Send the MSG_NEWKEYS */ -- if (ssh_buffer_add_u8(session->out_buffer, SSH2_MSG_NEWKEYS) < 0) { -- goto error; -- } -- -- rc=ssh_packet_send(session); -+ rc = ssh_packet_send_newkeys(session); - if (rc == SSH_ERROR) { - goto error; - } -- -- SSH_LOG(SSH_LOG_PROTOCOL, "SSH_MSG_NEWKEYS sent"); - session->dh_handshake_state = DH_STATE_NEWKEYS_SENT; - - return SSH_PACKET_USED; -diff --git a/src/ecdh_crypto.c b/src/ecdh_crypto.c -index 51084b7a..069b1372 100644 ---- a/src/ecdh_crypto.c -+++ b/src/ecdh_crypto.c -@@ -619,18 +619,12 @@ SSH_PACKET_CALLBACK(ssh_packet_server_ecdh_init){ - goto error; - } - -- /* Send the MSG_NEWKEYS */ -- rc = ssh_buffer_add_u8(session->out_buffer, SSH2_MSG_NEWKEYS); -- if (rc < 0) { -- goto error; -- } -- - session->dh_handshake_state = DH_STATE_NEWKEYS_SENT; -- rc = ssh_packet_send(session); -- if (rc == SSH_ERROR){ -+ /* Send the MSG_NEWKEYS */ -+ rc = ssh_packet_send_newkeys(session); -+ if (rc == SSH_ERROR) { - goto error; - } -- SSH_LOG(SSH_LOG_PROTOCOL, "SSH_MSG_NEWKEYS sent"); - - return SSH_PACKET_USED; - error: -diff --git a/src/ecdh_gcrypt.c b/src/ecdh_gcrypt.c -index 235f2904..3d9d426f 100644 ---- a/src/ecdh_gcrypt.c -+++ b/src/ecdh_gcrypt.c -@@ -372,17 +372,13 @@ SSH_PACKET_CALLBACK(ssh_packet_server_ecdh_init){ - goto out; - } - -- -+ session->dh_handshake_state = DH_STATE_NEWKEYS_SENT; - /* Send the MSG_NEWKEYS */ -- rc = ssh_buffer_add_u8(session->out_buffer, SSH2_MSG_NEWKEYS); -- if (rc != SSH_OK) { -+ rc = ssh_packet_send_newkeys(session); -+ if (rc == SSH_ERROR) { - goto out; - } - -- session->dh_handshake_state = DH_STATE_NEWKEYS_SENT; -- rc = ssh_packet_send(session); -- SSH_LOG(SSH_LOG_PROTOCOL, "SSH_MSG_NEWKEYS sent"); -- - out: - gcry_sexp_release(param); - gcry_sexp_release(key); -diff --git a/src/ecdh_mbedcrypto.c b/src/ecdh_mbedcrypto.c -index cfe017a0..dda73922 100644 ---- a/src/ecdh_mbedcrypto.c -+++ b/src/ecdh_mbedcrypto.c -@@ -318,16 +318,13 @@ SSH_PACKET_CALLBACK(ssh_packet_server_ecdh_init){ - goto out; - } - -- rc = ssh_buffer_add_u8(session->out_buffer, SSH2_MSG_NEWKEYS); -- if (rc < 0) { -- rc = SSH_ERROR; -+ session->dh_handshake_state = DH_STATE_NEWKEYS_SENT; -+ /* Send the MSG_NEWKEYS */ -+ rc = ssh_packet_send_newkeys(session); -+ if (rc == SSH_ERROR) { - goto out; - } - -- session->dh_handshake_state = DH_STATE_NEWKEYS_SENT; -- rc = ssh_packet_send(session); -- SSH_LOG(SSH_LOG_PROTOCOL, "SSH_MSG_NEWKEYS sent"); -- - out: - mbedtls_ecp_group_free(&grp); - if (rc == SSH_ERROR) { -diff --git a/src/kex.c b/src/kex.c -index b9455d2d..3818297b 100644 ---- a/src/kex.c -+++ b/src/kex.c -@@ -188,6 +188,9 @@ - - /* RFC 8308 */ - #define KEX_EXTENSION_CLIENT "ext-info-c" -+/* Strict kex mitigation against CVE-2023-48795 */ -+#define KEX_STRICT_CLIENT "kex-strict-c-v00@openssh.com" -+#define KEX_STRICT_SERVER "kex-strict-s-v00@openssh.com" - - /* Allowed algorithms in FIPS mode */ - #define FIPS_ALLOWED_CIPHERS "aes256-gcm@openssh.com,"\ -@@ -516,6 +519,27 @@ SSH_PACKET_CALLBACK(ssh_packet_kexinit) - session->first_kex_follows_guess_wrong ? "wrong" : "right"); - } - -+ /* -+ * handle the "strict KEX" feature. If supported by peer, then set up the -+ * flag and verify packet sequence numbers. -+ */ -+ if (server_kex) { -+ ok = ssh_match_group(crypto->client_kex.methods[SSH_KEX], -+ KEX_STRICT_CLIENT); -+ if (ok) { -+ SSH_LOG(SSH_LOG_DEBUG, "Client supports strict kex, enabling."); -+ session->flags |= SSH_SESSION_FLAG_KEX_STRICT; -+ } -+ } else { -+ /* client kex */ -+ ok = ssh_match_group(crypto->server_kex.methods[SSH_KEX], -+ KEX_STRICT_SERVER); -+ if (ok) { -+ SSH_LOG(SSH_LOG_DEBUG, "Server supports strict kex, enabling."); -+ session->flags |= SSH_SESSION_FLAG_KEX_STRICT; -+ } -+ } -+ - if (server_kex) { - /* - * If client sent a ext-info-c message in the kex list, it supports -@@ -792,21 +816,21 @@ int ssh_set_client_kex(ssh_session session) - return SSH_OK; - } - -- /* Here we append ext-info-c to the list of kex algorithms */ -+ /* Here we append ext-info-c and kex-strict-c-v00@openssh.com to the list of kex algorithms */ - kex = client->methods[SSH_KEX]; - len = strlen(kex); -- if (len + strlen(KEX_EXTENSION_CLIENT) + 2 < len) { -+ /* Comma, comma, nul byte */ -+ kex_len = len + 1 + strlen(KEX_EXTENSION_CLIENT) + 1 + strlen(KEX_STRICT_CLIENT ) + 1; -+ if (kex_len >= MAX_PACKET_LEN) { - /* Overflow */ - return SSH_ERROR; - } -- kex_len = len + strlen(KEX_EXTENSION_CLIENT) + 2; /* comma, NULL */ - kex_tmp = realloc(kex, kex_len); - if (kex_tmp == NULL) { -- free(kex); - ssh_set_error_oom(session); - return SSH_ERROR; - } -- snprintf(kex_tmp + len, kex_len - len, ",%s", KEX_EXTENSION_CLIENT); -+ snprintf(kex_tmp + len, kex_len - len, ",%s,%s", KEX_EXTENSION_CLIENT, KEX_STRICT_CLIENT); - client->methods[SSH_KEX] = kex_tmp; - - return SSH_OK; -diff --git a/src/packet.c b/src/packet.c -index eb7eb42a..ea73f9ad 100644 ---- a/src/packet.c -+++ b/src/packet.c -@@ -1314,6 +1314,19 @@ ssh_packet_socket_callback(const void *data, size_t receivedlen, void *user) - } - #endif /* WITH_ZLIB */ - payloadsize = ssh_buffer_get_len(session->in_buffer); -+ if (session->recv_seq == UINT32_MAX) { -+ /* Overflowing sequence numbers is always fishy */ -+ if (crypto == NULL) { -+ /* don't allow sequence number overflow when unencrypted */ -+ ssh_set_error(session, -+ SSH_FATAL, -+ "Incoming sequence number overflow"); -+ goto error; -+ } else { -+ SSH_LOG(SSH_LOG_WARNING, -+ "Incoming sequence number overflow"); -+ } -+ } - session->recv_seq++; - if (crypto != NULL) { - struct ssh_cipher_struct *cipher = NULL; -@@ -1338,7 +1351,19 @@ ssh_packet_socket_callback(const void *data, size_t receivedlen, void *user) - "comp=%" PRIu32 ",payload=%" PRIu32 "]", - session->in_packet.type, packet_len, padding, compsize, - payloadsize); -+ if (crypto == NULL) { -+ /* In strict kex, only a few packets are allowed. Taint the session -+ * if we received packets that are normally allowed but to be -+ * refused if we are in strict kex when KEX is over. -+ */ -+ uint8_t type = session->in_packet.type; - -+ if (type != SSH2_MSG_KEXINIT && type != SSH2_MSG_NEWKEYS && -+ (type < SSH2_MSG_KEXDH_INIT || -+ type > SSH2_MSG_KEX_DH_GEX_REQUEST)) { -+ session->flags |= SSH_SESSION_FLAG_KEX_TAINTED; -+ } -+ } - /* Check if the packet is expected */ - filter_result = ssh_packet_incoming_filter(session); - -@@ -1354,6 +1379,9 @@ ssh_packet_socket_callback(const void *data, size_t receivedlen, void *user) - session->in_packet.type); - goto error; - case SSH_PACKET_UNKNOWN: -+ if (crypto == NULL) { -+ session->flags |= SSH_SESSION_FLAG_KEX_TAINTED; -+ } - ssh_packet_send_unimplemented(session, session->recv_seq - 1); - break; - } -@@ -1529,7 +1557,33 @@ void ssh_packet_process(ssh_session session, uint8_t type) - SSH_LOG(SSH_LOG_RARE, "Failed to send unimplemented: %s", - ssh_get_error(session)); - } -+ if (session->current_crypto == NULL) { -+ session->flags |= SSH_SESSION_FLAG_KEX_TAINTED; -+ } -+ } -+} -+ -+/** @internal -+ * @brief sends a SSH_MSG_NEWKEYS when enabling the new negotiated ciphers -+ * @param session the SSH session -+ * @return SSH_ERROR on error, else SSH_OK -+ */ -+int ssh_packet_send_newkeys(ssh_session session) -+{ -+ int rc; -+ -+ /* Send the MSG_NEWKEYS */ -+ rc = ssh_buffer_add_u8(session->out_buffer, SSH2_MSG_NEWKEYS); -+ if (rc < 0) { -+ return rc; - } -+ -+ rc = ssh_packet_send(session); -+ if (rc == SSH_ERROR) { -+ return rc; -+ } -+ SSH_LOG(SSH_LOG_DEBUG, "SSH_MSG_NEWKEYS sent"); -+ return rc; - } - - /** @internal -@@ -1842,6 +1896,10 @@ int ssh_packet_send(ssh_session session) - if (rc == SSH_OK && type == SSH2_MSG_NEWKEYS) { - struct ssh_iterator *it; - -+ if (session->flags & SSH_SESSION_FLAG_KEX_STRICT) { -+ /* reset packet sequence number when running in strict kex mode */ -+ session->send_seq = 0; -+ } - for (it = ssh_list_get_iterator(session->out_queue); - it != NULL; - it = ssh_list_get_iterator(session->out_queue)) { -diff --git a/src/packet_cb.c b/src/packet_cb.c -index 0ecf8771..2f364c26 100644 ---- a/src/packet_cb.c -+++ b/src/packet_cb.c -@@ -115,6 +115,18 @@ SSH_PACKET_CALLBACK(ssh_packet_newkeys){ - goto error; - } - -+ if (session->flags & SSH_SESSION_FLAG_KEX_STRICT) { -+ /* reset packet sequence number when running in strict kex mode */ -+ session->recv_seq = 0; -+ /* Check that we aren't tainted */ -+ if (session->flags & SSH_SESSION_FLAG_KEX_TAINTED) { -+ ssh_set_error(session, -+ SSH_FATAL, -+ "Received unexpected packets in strict KEX mode."); -+ goto error; -+ } -+ } -+ - if(session->server){ - /* server things are done in server.c */ - session->dh_handshake_state=DH_STATE_FINISHED; --- -2.33.0 - diff --git a/backport-0012-CVE-2023-48795-Server-side-mitigations.patch b/backport-0012-CVE-2023-48795-Server-side-mitigations.patch deleted file mode 100644 index 6ff8921ab3aebfe2457c4e7c0d02bf57023b6212..0000000000000000000000000000000000000000 --- a/backport-0012-CVE-2023-48795-Server-side-mitigations.patch +++ /dev/null @@ -1,122 +0,0 @@ -From 0870c8db28be9eb457ee3d4f9a168959d9507efd Mon Sep 17 00:00:00 2001 -From: Aris Adamantiadis -Date: Tue, 12 Dec 2023 23:30:26 +0100 -Subject: [PATCH 12/20] CVE-2023-48795: Server side mitigations - -Signed-off-by: Aris Adamantiadis -Signed-off-by: Jakub Jelen -Reviewed-by: Andreas Schneider ---- - include/libssh/kex.h | 1 + - src/kex.c | 46 ++++++++++++++++++++++++++++++++++---------- - src/server.c | 8 +++++++- - 3 files changed, 44 insertions(+), 11 deletions(-) - -diff --git a/include/libssh/kex.h b/include/libssh/kex.h -index ede7fa8a..ba98fded 100644 ---- a/include/libssh/kex.h -+++ b/include/libssh/kex.h -@@ -40,6 +40,7 @@ SSH_PACKET_CALLBACK(ssh_packet_kexinit); - int ssh_send_kex(ssh_session session); - void ssh_list_kex(struct ssh_kex_struct *kex); - int ssh_set_client_kex(ssh_session session); -+int ssh_kex_append_extensions(ssh_session session, struct ssh_kex_struct *pkex); - int ssh_kex_select_methods(ssh_session session); - int ssh_verify_existing_algo(enum ssh_kex_types_e algo, const char *name); - char *ssh_keep_known_algos(enum ssh_kex_types_e algo, const char *list); -diff --git a/src/kex.c b/src/kex.c -index 3818297b..9ad671db 100644 ---- a/src/kex.c -+++ b/src/kex.c -@@ -763,11 +763,8 @@ int ssh_set_client_kex(ssh_session session) - { - struct ssh_kex_struct *client = &session->next_crypto->client_kex; - const char *wanted; -- char *kex = NULL; -- char *kex_tmp = NULL; - int ok; - int i; -- size_t kex_len, len; - - /* Skip if already set, for example for the rekey or when we do the guessing - * it could have been already used to make some protocol decisions. */ -@@ -816,11 +813,33 @@ int ssh_set_client_kex(ssh_session session) - return SSH_OK; - } - -- /* Here we append ext-info-c and kex-strict-c-v00@openssh.com to the list of kex algorithms */ -- kex = client->methods[SSH_KEX]; -+ ok = ssh_kex_append_extensions(session, client); -+ if (ok != SSH_OK){ -+ return ok; -+ } -+ -+ return SSH_OK; -+} -+ -+int ssh_kex_append_extensions(ssh_session session, struct ssh_kex_struct *pkex) -+{ -+ char *kex = NULL; -+ char *kex_tmp = NULL; -+ size_t kex_len, len; -+ -+ /* Here we append ext-info-c and kex-strict-c-v00@openssh.com for client -+ * and kex-strict-s-v00@openssh.com for server to the list of kex algorithms -+ */ -+ kex = pkex->methods[SSH_KEX]; - len = strlen(kex); -- /* Comma, comma, nul byte */ -- kex_len = len + 1 + strlen(KEX_EXTENSION_CLIENT) + 1 + strlen(KEX_STRICT_CLIENT ) + 1; -+ if (session->server) { -+ /* Comma, nul byte */ -+ kex_len = len + 1 + strlen(KEX_STRICT_SERVER) + 1; -+ } else { -+ /* Comma, comma, nul byte */ -+ kex_len = len + 1 + strlen(KEX_EXTENSION_CLIENT) + 1 + -+ strlen(KEX_STRICT_CLIENT) + 1; -+ } - if (kex_len >= MAX_PACKET_LEN) { - /* Overflow */ - return SSH_ERROR; -@@ -830,9 +849,16 @@ int ssh_set_client_kex(ssh_session session) - ssh_set_error_oom(session); - return SSH_ERROR; - } -- snprintf(kex_tmp + len, kex_len - len, ",%s,%s", KEX_EXTENSION_CLIENT, KEX_STRICT_CLIENT); -- client->methods[SSH_KEX] = kex_tmp; -- -+ if (session->server){ -+ snprintf(kex_tmp + len, kex_len - len, ",%s", KEX_STRICT_SERVER); -+ } else { -+ snprintf(kex_tmp + len, -+ kex_len - len, -+ ",%s,%s", -+ KEX_EXTENSION_CLIENT, -+ KEX_STRICT_CLIENT); -+ } -+ pkex->methods[SSH_KEX] = kex_tmp; - return SSH_OK; - } - -diff --git a/src/server.c b/src/server.c -index dc070a73..70b90899 100644 ---- a/src/server.c -+++ b/src/server.c -@@ -195,7 +195,13 @@ int server_set_kex(ssh_session session) - } - } - -- return 0; -+ /* Do not append the extensions during rekey */ -+ if (session->flags & SSH_SESSION_FLAG_AUTHENTICATED) { -+ return SSH_OK; -+ } -+ -+ rc = ssh_kex_append_extensions(session, server); -+ return rc; - } - - int ssh_server_init_kex(ssh_session session) { --- -2.33.0 - diff --git a/backport-0013-CVE-2023-48795-Strip-extensions-from-both-kex-lists-.patch b/backport-0013-CVE-2023-48795-Strip-extensions-from-both-kex-lists-.patch deleted file mode 100644 index e4511f2d26743b2172e1a8075cfc6d15c60804c6..0000000000000000000000000000000000000000 --- a/backport-0013-CVE-2023-48795-Strip-extensions-from-both-kex-lists-.patch +++ /dev/null @@ -1,43 +0,0 @@ -From 5846e57538c750c5ce67df887d09fa99861c79c6 Mon Sep 17 00:00:00 2001 -From: Jakub Jelen -Date: Thu, 14 Dec 2023 12:22:01 +0100 -Subject: [PATCH 13/20] CVE-2023-48795: Strip extensions from both kex lists - for matching - -Signed-off-by: Jakub Jelen -Reviewed-by: Andreas Schneider ---- - src/kex.c | 16 ++++++++++++---- - 1 file changed, 12 insertions(+), 4 deletions(-) - -diff --git a/src/kex.c b/src/kex.c -index 9ad671db..fbc70cf4 100644 ---- a/src/kex.c -+++ b/src/kex.c -@@ -961,11 +961,19 @@ int ssh_kex_select_methods (ssh_session session) - enum ssh_key_exchange_e kex_type; - int i; - -- /* Here we should drop the ext-info-c from the list so we avoid matching. -+ /* Here we should drop the extensions from the list so we avoid matching. - * it. We added it to the end, so we can just truncate the string here */ -- ext_start = strstr(client->methods[SSH_KEX], ","KEX_EXTENSION_CLIENT); -- if (ext_start != NULL) { -- ext_start[0] = '\0'; -+ if (session->client) { -+ ext_start = strstr(client->methods[SSH_KEX], "," KEX_EXTENSION_CLIENT); -+ if (ext_start != NULL) { -+ ext_start[0] = '\0'; -+ } -+ } -+ if (session->server) { -+ ext_start = strstr(server->methods[SSH_KEX], "," KEX_STRICT_SERVER); -+ if (ext_start != NULL) { -+ ext_start[0] = '\0'; -+ } - } - - for (i = 0; i < SSH_KEX_METHODS; i++) { --- -2.33.0 - diff --git a/backport-0014-CVE-2023-48795-tests-Adjust-calculation-to-strict-ke.patch b/backport-0014-CVE-2023-48795-tests-Adjust-calculation-to-strict-ke.patch deleted file mode 100644 index 8616db29525d4be564ff540ed6baa4a96ab2912c..0000000000000000000000000000000000000000 --- a/backport-0014-CVE-2023-48795-tests-Adjust-calculation-to-strict-ke.patch +++ /dev/null @@ -1,105 +0,0 @@ -From 89df759200d31fc79fbbe213d8eda0d329eebf6d Mon Sep 17 00:00:00 2001 -From: Jakub Jelen -Date: Thu, 14 Dec 2023 12:47:48 +0100 -Subject: [PATCH 14/20] CVE-2023-48795: tests: Adjust calculation to strict kex - -Signed-off-by: Jakub Jelen -Reviewed-by: Andreas Schneider ---- - tests/client/torture_rekey.c | 55 ++++++++++++++++++++---------------- - 1 file changed, 31 insertions(+), 24 deletions(-) - -diff --git a/tests/client/torture_rekey.c b/tests/client/torture_rekey.c -index ccd5ae2c..57e03e3f 100644 ---- a/tests/client/torture_rekey.c -+++ b/tests/client/torture_rekey.c -@@ -148,6 +148,29 @@ static void torture_rekey_default(void **state) - ssh_disconnect(s->ssh.session); - } - -+static void sanity_check_session(void **state) -+{ -+ struct torture_state *s = *state; -+ struct ssh_crypto_struct *c = NULL; -+ -+ c = s->ssh.session->current_crypto; -+ assert_non_null(c); -+ assert_int_equal(c->in_cipher->max_blocks, -+ bytes / c->in_cipher->blocksize); -+ assert_int_equal(c->out_cipher->max_blocks, -+ bytes / c->out_cipher->blocksize); -+ /* when strict kex is used, the newkeys reset the sequence number */ -+ if ((s->ssh.session->flags & SSH_SESSION_FLAG_KEX_STRICT) != 0) { -+ assert_int_equal(c->out_cipher->packets, s->ssh.session->send_seq); -+ assert_int_equal(c->in_cipher->packets, s->ssh.session->recv_seq); -+ } else { -+ /* Otherwise we have less encrypted packets than transferred -+ * (first are not encrypted) */ -+ assert_true(c->out_cipher->packets < s->ssh.session->send_seq); -+ assert_true(c->in_cipher->packets < s->ssh.session->recv_seq); -+ } -+} -+ - /* We lower the rekey limits manually and check that the rekey - * really happens when sending data - */ -@@ -166,16 +189,10 @@ static void torture_rekey_send(void **state) - rc = ssh_connect(s->ssh.session); - assert_ssh_return_code(s->ssh.session, rc); - -- /* The blocks limit is set correctly */ -- c = s->ssh.session->current_crypto; -- assert_int_equal(c->in_cipher->max_blocks, -- bytes / c->in_cipher->blocksize); -- assert_int_equal(c->out_cipher->max_blocks, -- bytes / c->out_cipher->blocksize); -- /* We should have less encrypted packets than transferred (first are not encrypted) */ -- assert_true(c->out_cipher->packets < s->ssh.session->send_seq); -- assert_true(c->in_cipher->packets < s->ssh.session->recv_seq); -+ sanity_check_session(state); - /* Copy the initial secret hash = session_id so we know we changed keys later */ -+ c = s->ssh.session->current_crypto; -+ assert_non_null(c); - secret_hash = malloc(c->digest_len); - assert_non_null(secret_hash); - memcpy(secret_hash, c->secret_hash, c->digest_len); -@@ -273,15 +290,10 @@ static void torture_rekey_recv(void **state) - mode_t mask; - int rc; - -- /* The blocks limit is set correctly */ -+ sanity_check_session(state); -+ /* Copy the initial secret hash = session_id so we know we changed keys later */ - c = s->ssh.session->current_crypto; - assert_non_null(c); -- assert_int_equal(c->in_cipher->max_blocks, bytes / c->in_cipher->blocksize); -- assert_int_equal(c->out_cipher->max_blocks, bytes / c->out_cipher->blocksize); -- /* We should have less encrypted packets than transferred (first are not encrypted) */ -- assert_true(c->out_cipher->packets < s->ssh.session->send_seq); -- assert_true(c->in_cipher->packets < s->ssh.session->recv_seq); -- /* Copy the initial secret hash = session_id so we know we changed keys later */ - secret_hash = malloc(c->digest_len); - assert_non_null(secret_hash); - memcpy(secret_hash, c->secret_hash, c->digest_len); -@@ -468,15 +480,10 @@ static void torture_rekey_different_kex(void **state) - assert_ssh_return_code(s->ssh.session, rc); - - /* The blocks limit is set correctly */ -- c = s->ssh.session->current_crypto; -- assert_int_equal(c->in_cipher->max_blocks, -- bytes / c->in_cipher->blocksize); -- assert_int_equal(c->out_cipher->max_blocks, -- bytes / c->out_cipher->blocksize); -- /* We should have less encrypted packets than transferred (first are not encrypted) */ -- assert_true(c->out_cipher->packets < s->ssh.session->send_seq); -- assert_true(c->in_cipher->packets < s->ssh.session->recv_seq); -+ sanity_check_session(state); - /* Copy the initial secret hash = session_id so we know we changed keys later */ -+ c = s->ssh.session->current_crypto; -+ assert_non_null(c); - secret_hash = malloc(c->digest_len); - assert_non_null(secret_hash); - memcpy(secret_hash, c->secret_hash, c->digest_len); --- -2.33.0 - diff --git a/backport-0015-CVE-2023-6918-kdf-Reformat.patch b/backport-0015-CVE-2023-6918-kdf-Reformat.patch deleted file mode 100644 index b33427586091b11429a8e91a322c8921da543045..0000000000000000000000000000000000000000 --- a/backport-0015-CVE-2023-6918-kdf-Reformat.patch +++ /dev/null @@ -1,72 +0,0 @@ -From 610d7a09f99c601224ae2aa3d3de7e75b1d284dd Mon Sep 17 00:00:00 2001 -From: Jakub Jelen -Date: Fri, 15 Dec 2023 10:30:09 +0100 -Subject: [PATCH 15/20] CVE-2023-6918: kdf: Reformat - -Signed-off-by: Jakub Jelen -Reviewed-by: Andreas Schneider ---- - src/kdf.c | 20 +++++++++++--------- - 1 file changed, 11 insertions(+), 9 deletions(-) - -diff --git a/src/kdf.c b/src/kdf.c -index 44f06631..987ae972 100644 ---- a/src/kdf.c -+++ b/src/kdf.c -@@ -58,7 +58,7 @@ static ssh_mac_ctx ssh_mac_ctx_init(enum ssh_kdf_digest type) - } - - ctx->digest_type = type; -- switch(type){ -+ switch (type) { - case SSH_KDF_SHA1: - ctx->ctx.sha1_ctx = sha1_init(); - return ctx; -@@ -79,7 +79,7 @@ static ssh_mac_ctx ssh_mac_ctx_init(enum ssh_kdf_digest type) - - static void ssh_mac_update(ssh_mac_ctx ctx, const void *data, size_t len) - { -- switch(ctx->digest_type){ -+ switch (ctx->digest_type) { - case SSH_KDF_SHA1: - sha1_update(ctx->ctx.sha1_ctx, data, len); - break; -@@ -97,26 +97,28 @@ static void ssh_mac_update(ssh_mac_ctx ctx, const void *data, size_t len) - - static void ssh_mac_final(unsigned char *md, ssh_mac_ctx ctx) - { -- switch(ctx->digest_type){ -+ switch (ctx->digest_type) { - case SSH_KDF_SHA1: -- sha1_final(md,ctx->ctx.sha1_ctx); -+ sha1_final(md, ctx->ctx.sha1_ctx); - break; - case SSH_KDF_SHA256: -- sha256_final(md,ctx->ctx.sha256_ctx); -+ sha256_final(md, ctx->ctx.sha256_ctx); - break; - case SSH_KDF_SHA384: -- sha384_final(md,ctx->ctx.sha384_ctx); -+ sha384_final(md, ctx->ctx.sha384_ctx); - break; - case SSH_KDF_SHA512: -- sha512_final(md,ctx->ctx.sha512_ctx); -+ sha512_final(md, ctx->ctx.sha512_ctx); - break; - } - SAFE_FREE(ctx); - } - - int sshkdf_derive_key(struct ssh_crypto_struct *crypto, -- unsigned char *key, size_t key_len, -- uint8_t key_type, unsigned char *output, -+ unsigned char *key, -+ size_t key_len, -+ uint8_t key_type, -+ unsigned char *output, - size_t requested_len) - { - /* Can't use VLAs with Visual Studio, so allocate the biggest --- -2.33.0 - diff --git a/backport-0016-CVE-2023-6918-Remove-unused-evp-functions-and-types.patch b/backport-0016-CVE-2023-6918-Remove-unused-evp-functions-and-types.patch deleted file mode 100644 index d3d3a39103c6932cf3b405ca2f6e01234d4b801a..0000000000000000000000000000000000000000 --- a/backport-0016-CVE-2023-6918-Remove-unused-evp-functions-and-types.patch +++ /dev/null @@ -1,289 +0,0 @@ -From 63ff242131c8e6d98917456f71f6d33b9ef3a763 Mon Sep 17 00:00:00 2001 -From: Jakub Jelen -Date: Fri, 15 Dec 2023 12:55:27 +0100 -Subject: [PATCH 16/20] CVE-2023-6918: Remove unused evp functions and types - -Signed-off-by: Jakub Jelen -Reviewed-by: Andreas Schneider ---- - include/libssh/libcrypto.h | 5 --- - include/libssh/libgcrypt.h | 1 - - include/libssh/libmbedcrypto.h | 1 - - include/libssh/wrapper.h | 4 -- - src/libcrypto.c | 54 ------------------------- - src/libgcrypt.c | 53 ------------------------ - src/libmbedcrypto.c | 74 ---------------------------------- - 7 files changed, 192 deletions(-) - -diff --git a/include/libssh/libcrypto.h b/include/libssh/libcrypto.h -index 16e5f98f..87f30a4d 100644 ---- a/include/libssh/libcrypto.h -+++ b/include/libssh/libcrypto.h -@@ -39,11 +39,6 @@ typedef EVP_MD_CTX* SHA384CTX; - typedef EVP_MD_CTX* SHA512CTX; - typedef EVP_MD_CTX* MD5CTX; - typedef EVP_MD_CTX* HMACCTX; --#ifdef HAVE_ECC --typedef EVP_MD_CTX *EVPCTX; --#else --typedef void *EVPCTX; --#endif - - #define SHA_DIGEST_LEN SHA_DIGEST_LENGTH - #define SHA256_DIGEST_LEN SHA256_DIGEST_LENGTH -diff --git a/include/libssh/libgcrypt.h b/include/libssh/libgcrypt.h -index e4087fd2..c6afc22e 100644 ---- a/include/libssh/libgcrypt.h -+++ b/include/libssh/libgcrypt.h -@@ -32,7 +32,6 @@ typedef gcry_md_hd_t SHA384CTX; - typedef gcry_md_hd_t SHA512CTX; - typedef gcry_md_hd_t MD5CTX; - typedef gcry_md_hd_t HMACCTX; --typedef gcry_md_hd_t EVPCTX; - #define SHA_DIGEST_LENGTH 20 - #define SHA_DIGEST_LEN SHA_DIGEST_LENGTH - #define MD5_DIGEST_LEN 16 -diff --git a/include/libssh/libmbedcrypto.h b/include/libssh/libmbedcrypto.h -index e6fc393c..540a025b 100644 ---- a/include/libssh/libmbedcrypto.h -+++ b/include/libssh/libmbedcrypto.h -@@ -41,7 +41,6 @@ typedef mbedtls_md_context_t *SHA384CTX; - typedef mbedtls_md_context_t *SHA512CTX; - typedef mbedtls_md_context_t *MD5CTX; - typedef mbedtls_md_context_t *HMACCTX; --typedef mbedtls_md_context_t *EVPCTX; - - #define SHA_DIGEST_LENGTH 20 - #define SHA_DIGEST_LEN SHA_DIGEST_LENGTH -diff --git a/include/libssh/wrapper.h b/include/libssh/wrapper.h -index 36589cff..07e64018 100644 ---- a/include/libssh/wrapper.h -+++ b/include/libssh/wrapper.h -@@ -95,10 +95,6 @@ void sha512_update(SHA512CTX c, const void *data, size_t len); - void sha512_final(unsigned char *md,SHA512CTX c); - void sha512(const unsigned char *digest, size_t len, unsigned char *hash); - --void evp(int nid, unsigned char *digest, size_t len, unsigned char *hash, unsigned int *hlen); --EVPCTX evp_init(int nid); --void evp_update(EVPCTX ctx, const void *data, size_t len); --void evp_final(EVPCTX ctx, unsigned char *md, unsigned int *mdlen); - - HMACCTX hmac_init(const void *key,size_t len, enum ssh_hmac_e type); - int hmac_update(HMACCTX c, const void *data, size_t len); -diff --git a/src/libcrypto.c b/src/libcrypto.c -index ebdca6e0..4f945d90 100644 ---- a/src/libcrypto.c -+++ b/src/libcrypto.c -@@ -125,60 +125,6 @@ ENGINE *pki_get_engine(void) - return engine; - } - --#ifdef HAVE_OPENSSL_ECC --static const EVP_MD *nid_to_evpmd(int nid) --{ -- switch (nid) { -- case NID_X9_62_prime256v1: -- return EVP_sha256(); -- case NID_secp384r1: -- return EVP_sha384(); -- case NID_secp521r1: -- return EVP_sha512(); -- default: -- return NULL; -- } -- -- return NULL; --} -- --void evp(int nid, unsigned char *digest, size_t len, unsigned char *hash, unsigned int *hlen) --{ -- const EVP_MD *evp_md = nid_to_evpmd(nid); -- EVP_MD_CTX *md = EVP_MD_CTX_new(); -- -- EVP_DigestInit(md, evp_md); -- EVP_DigestUpdate(md, digest, len); -- EVP_DigestFinal(md, hash, hlen); -- EVP_MD_CTX_free(md); --} -- --EVPCTX evp_init(int nid) --{ -- const EVP_MD *evp_md = nid_to_evpmd(nid); -- -- EVPCTX ctx = EVP_MD_CTX_new(); -- if (ctx == NULL) { -- return NULL; -- } -- -- EVP_DigestInit(ctx, evp_md); -- -- return ctx; --} -- --void evp_update(EVPCTX ctx, const void *data, size_t len) --{ -- EVP_DigestUpdate(ctx, data, len); --} -- --void evp_final(EVPCTX ctx, unsigned char *md, unsigned int *mdlen) --{ -- EVP_DigestFinal(ctx, md, mdlen); -- EVP_MD_CTX_free(ctx); --} --#endif /* HAVE_OPENSSL_ECC */ -- - #ifdef HAVE_OPENSSL_EVP_KDF_CTX - #if OPENSSL_VERSION_NUMBER < 0x30000000L - static const EVP_MD *sshkdf_digest_to_md(enum ssh_kdf_digest digest_type) -diff --git a/src/libgcrypt.c b/src/libgcrypt.c -index 2e44a53c..f410d997 100644 ---- a/src/libgcrypt.c -+++ b/src/libgcrypt.c -@@ -69,59 +69,6 @@ static int alloc_key(struct ssh_cipher_struct *cipher) { - void ssh_reseed(void){ - } - --#ifdef HAVE_GCRYPT_ECC --static int nid_to_md_algo(int nid) --{ -- switch (nid) { -- case NID_gcrypt_nistp256: -- return GCRY_MD_SHA256; -- case NID_gcrypt_nistp384: -- return GCRY_MD_SHA384; -- case NID_gcrypt_nistp521: -- return GCRY_MD_SHA512; -- } -- return GCRY_MD_NONE; --} -- --void evp(int nid, unsigned char *digest, size_t len, -- unsigned char *hash, unsigned int *hlen) --{ -- int algo = nid_to_md_algo(nid); -- -- /* Note: What gcrypt calls 'hash' is called 'digest' here and -- vice-versa. */ -- gcry_md_hash_buffer(algo, hash, digest, len); -- *hlen = gcry_md_get_algo_dlen(algo); --} -- --EVPCTX evp_init(int nid) --{ -- gcry_error_t err; -- int algo = nid_to_md_algo(nid); -- EVPCTX ctx; -- -- err = gcry_md_open(&ctx, algo, 0); -- if (err) { -- return NULL; -- } -- -- return ctx; --} -- --void evp_update(EVPCTX ctx, const void *data, size_t len) --{ -- gcry_md_write(ctx, data, len); --} -- --void evp_final(EVPCTX ctx, unsigned char *md, unsigned int *mdlen) --{ -- int algo = gcry_md_get_algo(ctx); -- *mdlen = gcry_md_get_algo_dlen(algo); -- memcpy(md, gcry_md_read(ctx, algo), *mdlen); -- gcry_md_close(ctx); --} --#endif -- - int ssh_kdf(struct ssh_crypto_struct *crypto, - unsigned char *key, size_t key_len, - uint8_t key_type, unsigned char *output, -diff --git a/src/libmbedcrypto.c b/src/libmbedcrypto.c -index 594e5369..caa3b6e9 100644 ---- a/src/libmbedcrypto.c -+++ b/src/libmbedcrypto.c -@@ -51,80 +51,6 @@ void ssh_reseed(void) - mbedtls_ctr_drbg_reseed(&ssh_mbedtls_ctr_drbg, NULL, 0); - } - --static mbedtls_md_type_t nid_to_md_algo(int nid) --{ -- switch (nid) { -- case NID_mbedtls_nistp256: -- return MBEDTLS_MD_SHA256; -- case NID_mbedtls_nistp384: -- return MBEDTLS_MD_SHA384; -- case NID_mbedtls_nistp521: -- return MBEDTLS_MD_SHA512; -- } -- return MBEDTLS_MD_NONE; --} -- --void evp(int nid, unsigned char *digest, size_t len, -- unsigned char *hash, unsigned int *hlen) --{ -- mbedtls_md_type_t algo = nid_to_md_algo(nid); -- const mbedtls_md_info_t *md_info = -- mbedtls_md_info_from_type(algo); -- -- -- if (md_info != NULL) { -- *hlen = mbedtls_md_get_size(md_info); -- mbedtls_md(md_info, digest, len, hash); -- } --} -- --EVPCTX evp_init(int nid) --{ -- EVPCTX ctx = NULL; -- int rc; -- mbedtls_md_type_t algo = nid_to_md_algo(nid); -- const mbedtls_md_info_t *md_info = -- mbedtls_md_info_from_type(algo); -- -- if (md_info == NULL) { -- return NULL; -- } -- -- ctx = malloc(sizeof(mbedtls_md_context_t)); -- if (ctx == NULL) { -- return NULL; -- } -- -- mbedtls_md_init(ctx); -- -- rc = mbedtls_md_setup(ctx, md_info, 0); -- if (rc != 0) { -- SAFE_FREE(ctx); -- return NULL; -- } -- -- rc = mbedtls_md_starts(ctx); -- if (rc != 0) { -- SAFE_FREE(ctx); -- return NULL; -- } -- -- return ctx; --} -- --void evp_update(EVPCTX ctx, const void *data, size_t len) --{ -- mbedtls_md_update(ctx, data, len); --} -- --void evp_final(EVPCTX ctx, unsigned char *md, unsigned int *mdlen) --{ -- *mdlen = mbedtls_md_get_size(ctx->MBEDTLS_PRIVATE(md_info)); -- mbedtls_md_finish(ctx, md); -- mbedtls_md_free(ctx); -- SAFE_FREE(ctx); --} -- - int ssh_kdf(struct ssh_crypto_struct *crypto, - unsigned char *key, size_t key_len, - uint8_t key_type, unsigned char *output, --- -2.33.0 - diff --git a/backport-0017-CVE-2023-6918-Systematically-check-return-values-whe.patch b/backport-0017-CVE-2023-6918-Systematically-check-return-values-whe.patch deleted file mode 100644 index 5a8b00729909af5e91afee9dfe8eff8d2613c502..0000000000000000000000000000000000000000 --- a/backport-0017-CVE-2023-6918-Systematically-check-return-values-whe.patch +++ /dev/null @@ -1,1094 +0,0 @@ -From 8b66d037d575e5f3ce4d35964547ff8c7e75ff8e Mon Sep 17 00:00:00 2001 -From: Jakub Jelen -Date: Fri, 15 Dec 2023 12:55:54 +0100 -Subject: [PATCH 17/20] CVE-2023-6918: Systematically check return values when - calculating digests - -with all crypto backends - -Signed-off-by: Jakub Jelen -Reviewed-by: Andreas Schneider ---- - include/libssh/wrapper.h | 34 ++++---- - src/kdf.c | 96 ++++++++++++++++++----- - src/md_crypto.c | 161 ++++++++++++++++++++++++++++++-------- - src/md_gcrypt.c | 107 +++++++++++++++++++++---- - src/md_mbedcrypto.c | 165 +++++++++++++++++++++++++++++++-------- - src/session.c | 72 ++++++++++++----- - 6 files changed, 504 insertions(+), 131 deletions(-) - -diff --git a/include/libssh/wrapper.h b/include/libssh/wrapper.h -index 07e64018..b3e28eac 100644 ---- a/include/libssh/wrapper.h -+++ b/include/libssh/wrapper.h -@@ -72,29 +72,33 @@ struct ssh_crypto_struct; - - typedef struct ssh_mac_ctx_struct *ssh_mac_ctx; - MD5CTX md5_init(void); --void md5_update(MD5CTX c, const void *data, size_t len); --void md5_final(unsigned char *md,MD5CTX c); -+void md5_ctx_free(MD5CTX); -+int md5_update(MD5CTX c, const void *data, size_t len); -+int md5_final(unsigned char *md, MD5CTX c); - - SHACTX sha1_init(void); --void sha1_update(SHACTX c, const void *data, size_t len); --void sha1_final(unsigned char *md,SHACTX c); --void sha1(const unsigned char *digest,size_t len,unsigned char *hash); -+void sha1_ctx_free(SHACTX); -+int sha1_update(SHACTX c, const void *data, size_t len); -+int sha1_final(unsigned char *md,SHACTX c); -+int sha1(const unsigned char *digest,size_t len, unsigned char *hash); - - SHA256CTX sha256_init(void); --void sha256_update(SHA256CTX c, const void *data, size_t len); --void sha256_final(unsigned char *md,SHA256CTX c); --void sha256(const unsigned char *digest, size_t len, unsigned char *hash); -+void sha256_ctx_free(SHA256CTX); -+int sha256_update(SHA256CTX c, const void *data, size_t len); -+int sha256_final(unsigned char *md,SHA256CTX c); -+int sha256(const unsigned char *digest, size_t len, unsigned char *hash); - - SHA384CTX sha384_init(void); --void sha384_update(SHA384CTX c, const void *data, size_t len); --void sha384_final(unsigned char *md,SHA384CTX c); --void sha384(const unsigned char *digest, size_t len, unsigned char *hash); -+void sha384_ctx_free(SHA384CTX); -+int sha384_update(SHA384CTX c, const void *data, size_t len); -+int sha384_final(unsigned char *md,SHA384CTX c); -+int sha384(const unsigned char *digest, size_t len, unsigned char *hash); - - SHA512CTX sha512_init(void); --void sha512_update(SHA512CTX c, const void *data, size_t len); --void sha512_final(unsigned char *md,SHA512CTX c); --void sha512(const unsigned char *digest, size_t len, unsigned char *hash); -- -+void sha512_ctx_free(SHA512CTX); -+int sha512_update(SHA512CTX c, const void *data, size_t len); -+int sha512_final(unsigned char *md,SHA512CTX c); -+int sha512(const unsigned char *digest, size_t len, unsigned char *hash); - - HMACCTX hmac_init(const void *key,size_t len, enum ssh_hmac_e type); - int hmac_update(HMACCTX c, const void *data, size_t len); -diff --git a/src/kdf.c b/src/kdf.c -index 987ae972..a8e534e5 100644 ---- a/src/kdf.c -+++ b/src/kdf.c -@@ -77,41 +77,64 @@ static ssh_mac_ctx ssh_mac_ctx_init(enum ssh_kdf_digest type) - } - } - --static void ssh_mac_update(ssh_mac_ctx ctx, const void *data, size_t len) -+static void ssh_mac_ctx_free(ssh_mac_ctx ctx) - { -+ if (ctx == NULL) { -+ return; -+ } -+ - switch (ctx->digest_type) { - case SSH_KDF_SHA1: -- sha1_update(ctx->ctx.sha1_ctx, data, len); -+ sha1_ctx_free(ctx->ctx.sha1_ctx); - break; - case SSH_KDF_SHA256: -- sha256_update(ctx->ctx.sha256_ctx, data, len); -+ sha256_ctx_free(ctx->ctx.sha256_ctx); - break; - case SSH_KDF_SHA384: -- sha384_update(ctx->ctx.sha384_ctx, data, len); -+ sha384_ctx_free(ctx->ctx.sha384_ctx); - break; - case SSH_KDF_SHA512: -- sha512_update(ctx->ctx.sha512_ctx, data, len); -+ sha512_ctx_free(ctx->ctx.sha512_ctx); - break; - } -+ SAFE_FREE(ctx); -+} -+ -+static int ssh_mac_update(ssh_mac_ctx ctx, const void *data, size_t len) -+{ -+ switch (ctx->digest_type) { -+ case SSH_KDF_SHA1: -+ return sha1_update(ctx->ctx.sha1_ctx, data, len); -+ case SSH_KDF_SHA256: -+ return sha256_update(ctx->ctx.sha256_ctx, data, len); -+ case SSH_KDF_SHA384: -+ return sha384_update(ctx->ctx.sha384_ctx, data, len); -+ case SSH_KDF_SHA512: -+ return sha512_update(ctx->ctx.sha512_ctx, data, len); -+ } -+ return SSH_ERROR; - } - --static void ssh_mac_final(unsigned char *md, ssh_mac_ctx ctx) -+static int ssh_mac_final(unsigned char *md, ssh_mac_ctx ctx) - { -+ int rc = SSH_ERROR; -+ - switch (ctx->digest_type) { - case SSH_KDF_SHA1: -- sha1_final(md, ctx->ctx.sha1_ctx); -+ rc = sha1_final(md, ctx->ctx.sha1_ctx); - break; - case SSH_KDF_SHA256: -- sha256_final(md, ctx->ctx.sha256_ctx); -+ rc = sha256_final(md, ctx->ctx.sha256_ctx); - break; - case SSH_KDF_SHA384: -- sha384_final(md, ctx->ctx.sha384_ctx); -+ rc = sha384_final(md, ctx->ctx.sha384_ctx); - break; - case SSH_KDF_SHA512: -- sha512_final(md, ctx->ctx.sha512_ctx); -+ rc = sha512_final(md, ctx->ctx.sha512_ctx); - break; - } - SAFE_FREE(ctx); -+ return rc; - } - - int sshkdf_derive_key(struct ssh_crypto_struct *crypto, -@@ -126,6 +149,7 @@ int sshkdf_derive_key(struct ssh_crypto_struct *crypto, - unsigned char digest[DIGEST_MAX_LEN]; - size_t output_len = crypto->digest_len; - ssh_mac_ctx ctx; -+ int rc; - - if (DIGEST_MAX_LEN < crypto->digest_len) { - return -1; -@@ -136,11 +160,30 @@ int sshkdf_derive_key(struct ssh_crypto_struct *crypto, - return -1; - } - -- ssh_mac_update(ctx, key, key_len); -- ssh_mac_update(ctx, crypto->secret_hash, crypto->digest_len); -- ssh_mac_update(ctx, &key_type, 1); -- ssh_mac_update(ctx, crypto->session_id, crypto->session_id_len); -- ssh_mac_final(digest, ctx); -+ rc = ssh_mac_update(ctx, key, key_len); -+ if (rc != SSH_OK) { -+ ssh_mac_ctx_free(ctx); -+ return -1; -+ } -+ rc = ssh_mac_update(ctx, crypto->secret_hash, crypto->digest_len); -+ if (rc != SSH_OK) { -+ ssh_mac_ctx_free(ctx); -+ return -1; -+ } -+ rc = ssh_mac_update(ctx, &key_type, 1); -+ if (rc != SSH_OK) { -+ ssh_mac_ctx_free(ctx); -+ return -1; -+ } -+ rc = ssh_mac_update(ctx, crypto->session_id, crypto->session_id_len); -+ if (rc != SSH_OK) { -+ ssh_mac_ctx_free(ctx); -+ return -1; -+ } -+ rc = ssh_mac_final(digest, ctx); -+ if (rc != SSH_OK) { -+ return -1; -+ } - - if (requested_len < output_len) { - output_len = requested_len; -@@ -152,10 +195,25 @@ int sshkdf_derive_key(struct ssh_crypto_struct *crypto, - if (ctx == NULL) { - return -1; - } -- ssh_mac_update(ctx, key, key_len); -- ssh_mac_update(ctx, crypto->secret_hash, crypto->digest_len); -- ssh_mac_update(ctx, output, output_len); -- ssh_mac_final(digest, ctx); -+ rc = ssh_mac_update(ctx, key, key_len); -+ if (rc != SSH_OK) { -+ ssh_mac_ctx_free(ctx); -+ return -1; -+ } -+ rc = ssh_mac_update(ctx, crypto->secret_hash, crypto->digest_len); -+ if (rc != SSH_OK) { -+ ssh_mac_ctx_free(ctx); -+ return -1; -+ } -+ rc = ssh_mac_update(ctx, output, output_len); -+ if (rc != SSH_OK) { -+ ssh_mac_ctx_free(ctx); -+ return -1; -+ } -+ rc = ssh_mac_final(digest, ctx); -+ if (rc != SSH_OK) { -+ return -1; -+ } - if (requested_len < output_len + crypto->digest_len) { - memcpy(output + output_len, digest, requested_len - output_len); - } else { -diff --git a/src/md_crypto.c b/src/md_crypto.c -index f5104f04..f7cda8dd 100644 ---- a/src/md_crypto.c -+++ b/src/md_crypto.c -@@ -25,6 +25,7 @@ - #include "libssh/crypto.h" - #include "libssh/wrapper.h" - -+#include - #include - #include - #include -@@ -46,28 +47,49 @@ sha1_init(void) - } - - void -+sha1_ctx_free(SHACTX c) -+{ -+ EVP_MD_CTX_free(c); -+} -+ -+int - sha1_update(SHACTX c, const void *data, size_t len) - { -- EVP_DigestUpdate(c, data, len); -+ int rc = EVP_DigestUpdate(c, data, len); -+ if (rc != 1) { -+ return SSH_ERROR; -+ } -+ return SSH_OK; - } - --void -+int - sha1_final(unsigned char *md, SHACTX c) - { - unsigned int mdlen = 0; -+ int rc = EVP_DigestFinal(c, md, &mdlen); - -- EVP_DigestFinal(c, md, &mdlen); - EVP_MD_CTX_free(c); -+ if (rc != 1) { -+ return SSH_ERROR; -+ } -+ return SSH_OK; - } - --void -+int - sha1(const unsigned char *digest, size_t len, unsigned char *hash) - { - SHACTX c = sha1_init(); -- if (c != NULL) { -- sha1_update(c, digest, len); -- sha1_final(hash, c); -+ int rc; -+ -+ if (c == NULL) { -+ return SSH_ERROR; - } -+ rc = sha1_update(c, digest, len); -+ if (rc != SSH_OK) { -+ EVP_MD_CTX_free(c); -+ return SSH_ERROR; -+ } -+ return sha1_final(hash, c); - } - - SHA256CTX -@@ -87,28 +109,49 @@ sha256_init(void) - } - - void -+sha256_ctx_free(SHA256CTX c) -+{ -+ EVP_MD_CTX_free(c); -+} -+ -+int - sha256_update(SHA256CTX c, const void *data, size_t len) - { -- EVP_DigestUpdate(c, data, len); -+ int rc = EVP_DigestUpdate(c, data, len); -+ if (rc != 1) { -+ return SSH_ERROR; -+ } -+ return SSH_OK; - } - --void -+int - sha256_final(unsigned char *md, SHA256CTX c) - { - unsigned int mdlen = 0; -+ int rc = EVP_DigestFinal(c, md, &mdlen); - -- EVP_DigestFinal(c, md, &mdlen); - EVP_MD_CTX_free(c); -+ if (rc != 1) { -+ return SSH_ERROR; -+ } -+ return SSH_OK; - } - --void -+int - sha256(const unsigned char *digest, size_t len, unsigned char *hash) - { - SHA256CTX c = sha256_init(); -- if (c != NULL) { -- sha256_update(c, digest, len); -- sha256_final(hash, c); -+ int rc; -+ -+ if (c == NULL) { -+ return SSH_ERROR; -+ } -+ rc = sha256_update(c, digest, len); -+ if (rc != SSH_OK) { -+ EVP_MD_CTX_free(c); -+ return SSH_ERROR; - } -+ return sha256_final(hash, c); - } - - SHA384CTX -@@ -128,28 +171,49 @@ sha384_init(void) - } - - void -+sha384_ctx_free(SHA384CTX c) -+{ -+ EVP_MD_CTX_free(c); -+} -+ -+int - sha384_update(SHA384CTX c, const void *data, size_t len) - { -- EVP_DigestUpdate(c, data, len); -+ int rc = EVP_DigestUpdate(c, data, len); -+ if (rc != 1) { -+ return SSH_ERROR; -+ } -+ return SSH_OK; - } - --void -+int - sha384_final(unsigned char *md, SHA384CTX c) - { - unsigned int mdlen = 0; -+ int rc = EVP_DigestFinal(c, md, &mdlen); - -- EVP_DigestFinal(c, md, &mdlen); - EVP_MD_CTX_free(c); -+ if (rc != 1) { -+ return SSH_ERROR; -+ } -+ return SSH_OK; - } - --void -+int - sha384(const unsigned char *digest, size_t len, unsigned char *hash) - { - SHA384CTX c = sha384_init(); -- if (c != NULL) { -- sha384_update(c, digest, len); -- sha384_final(hash, c); -+ int rc; -+ -+ if (c == NULL) { -+ return SSH_ERROR; - } -+ rc = sha384_update(c, digest, len); -+ if (rc != SSH_OK) { -+ EVP_MD_CTX_free(c); -+ return SSH_ERROR; -+ } -+ return sha384_final(hash, c); - } - - SHA512CTX -@@ -169,28 +233,49 @@ sha512_init(void) - } - - void -+sha512_ctx_free(SHA512CTX c) -+{ -+ EVP_MD_CTX_free(c); -+} -+ -+int - sha512_update(SHA512CTX c, const void *data, size_t len) - { -- EVP_DigestUpdate(c, data, len); -+ int rc = EVP_DigestUpdate(c, data, len); -+ if (rc != 1) { -+ return SSH_ERROR; -+ } -+ return SSH_OK; - } - --void -+int - sha512_final(unsigned char *md, SHA512CTX c) - { - unsigned int mdlen = 0; -+ int rc = EVP_DigestFinal(c, md, &mdlen); - -- EVP_DigestFinal(c, md, &mdlen); - EVP_MD_CTX_free(c); -+ if (rc != 1) { -+ return SSH_ERROR; -+ } -+ return SSH_OK; - } - --void -+int - sha512(const unsigned char *digest, size_t len, unsigned char *hash) - { - SHA512CTX c = sha512_init(); -- if (c != NULL) { -- sha512_update(c, digest, len); -- sha512_final(hash, c); -+ int rc; -+ -+ if (c == NULL) { -+ return SSH_ERROR; -+ } -+ rc = sha512_update(c, digest, len); -+ if (rc != SSH_OK) { -+ EVP_MD_CTX_free(c); -+ return SSH_ERROR; - } -+ return sha512_final(hash, c); - } - - MD5CTX -@@ -210,16 +295,30 @@ md5_init(void) - } - - void -+md5_ctx_free(MD5CTX c) -+{ -+ EVP_MD_CTX_free(c); -+} -+ -+int - md5_update(MD5CTX c, const void *data, size_t len) - { -- EVP_DigestUpdate(c, data, len); -+ int rc = EVP_DigestUpdate(c, data, len); -+ if (rc != 1) { -+ return SSH_ERROR; -+ } -+ return SSH_OK; - } - --void -+int - md5_final(unsigned char *md, MD5CTX c) - { - unsigned int mdlen = 0; -+ int rc = EVP_DigestFinal(c, md, &mdlen); - -- EVP_DigestFinal(c, md, &mdlen); - EVP_MD_CTX_free(c); -+ if (rc != 1) { -+ return SSH_ERROR; -+ } -+ return SSH_OK; - } -diff --git a/src/md_gcrypt.c b/src/md_gcrypt.c -index 1f0a71f3..93c7b0d9 100644 ---- a/src/md_gcrypt.c -+++ b/src/md_gcrypt.c -@@ -36,24 +36,40 @@ sha1_init(void) - return ctx; - } - --void -+int - sha1_update(SHACTX c, const void *data, size_t len) - { - gcry_md_write(c, data, len); -+ return SSH_OK; - } - - void -+sha1_ctx_free(SHACTX c) -+{ -+ gcry_md_close(c); -+} -+ -+int - sha1_final(unsigned char *md, SHACTX c) - { -+ unsigned char *tmp = NULL; -+ - gcry_md_final(c); -- memcpy(md, gcry_md_read(c, 0), SHA_DIGEST_LEN); -+ tmp = gcry_md_read(c, 0); -+ if (tmp == NULL) { -+ gcry_md_close(c); -+ return SSH_ERROR; -+ } -+ memcpy(md, tmp, SHA_DIGEST_LEN); - gcry_md_close(c); -+ return SSH_OK; - } - --void -+int - sha1(const unsigned char *digest, size_t len, unsigned char *hash) - { - gcry_md_hash_buffer(GCRY_MD_SHA1, hash, digest, len); -+ return SSH_OK; - } - - SHA256CTX -@@ -66,23 +82,39 @@ sha256_init(void) - } - - void -+sha256_ctx_free(SHA256CTX c) -+{ -+ gcry_md_close(c); -+} -+ -+int - sha256_update(SHACTX c, const void *data, size_t len) - { - gcry_md_write(c, data, len); -+ return SSH_OK; - } - --void -+int - sha256_final(unsigned char *md, SHACTX c) - { -+ unsigned char *tmp = NULL; -+ - gcry_md_final(c); -- memcpy(md, gcry_md_read(c, 0), SHA256_DIGEST_LEN); -+ tmp = gcry_md_read(c, 0); -+ if (tmp == NULL) { -+ gcry_md_close(c); -+ return SSH_ERROR; -+ } -+ memcpy(md, tmp, SHA256_DIGEST_LEN); - gcry_md_close(c); -+ return SSH_OK; - } - --void -+int - sha256(const unsigned char *digest, size_t len, unsigned char *hash) - { - gcry_md_hash_buffer(GCRY_MD_SHA256, hash, digest, len); -+ return SSH_OK; - } - - SHA384CTX -@@ -95,23 +127,39 @@ sha384_init(void) - } - - void -+sha384_ctx_free(SHA384CTX c) -+{ -+ gcry_md_close(c); -+} -+ -+int - sha384_update(SHACTX c, const void *data, size_t len) - { - gcry_md_write(c, data, len); -+ return SSH_OK; - } - --void -+int - sha384_final(unsigned char *md, SHACTX c) - { -+ unsigned char *tmp = NULL; -+ - gcry_md_final(c); -- memcpy(md, gcry_md_read(c, 0), SHA384_DIGEST_LEN); -+ tmp = gcry_md_read(c, 0); -+ if (tmp == NULL) { -+ gcry_md_close(c); -+ return SSH_ERROR; -+ } -+ memcpy(md, tmp, SHA384_DIGEST_LEN); - gcry_md_close(c); -+ return SSH_OK; - } - --void -+int - sha384(const unsigned char *digest, size_t len, unsigned char *hash) - { - gcry_md_hash_buffer(GCRY_MD_SHA384, hash, digest, len); -+ return SSH_OK; - } - - SHA512CTX -@@ -124,23 +172,39 @@ sha512_init(void) - } - - void -+sha512_ctx_free(SHA512CTX c) -+{ -+ gcry_md_close(c); -+} -+ -+int - sha512_update(SHACTX c, const void *data, size_t len) - { - gcry_md_write(c, data, len); -+ return SSH_OK; - } - --void -+int - sha512_final(unsigned char *md, SHACTX c) - { -+ unsigned char *tmp = NULL; -+ - gcry_md_final(c); -- memcpy(md, gcry_md_read(c, 0), SHA512_DIGEST_LEN); -+ tmp = gcry_md_read(c, 0); -+ if (tmp == NULL) { -+ gcry_md_close(c); -+ return SSH_ERROR; -+ } -+ memcpy(md, tmp, SHA512_DIGEST_LEN); - gcry_md_close(c); -+ return SSH_OK; - } - --void -+int - sha512(const unsigned char *digest, size_t len, unsigned char *hash) - { - gcry_md_hash_buffer(GCRY_MD_SHA512, hash, digest, len); -+ return SSH_OK; - } - - MD5CTX -@@ -153,15 +217,30 @@ md5_init(void) - } - - void -+md5_ctx_free(MD5CTX c) -+{ -+ gcry_md_close(c); -+} -+ -+int - md5_update(MD5CTX c, const void *data, size_t len) - { - gcry_md_write(c, data, len); -+ return SSH_OK; - } - --void -+int - md5_final(unsigned char *md, MD5CTX c) - { -+ unsigned char *tmp = NULL; -+ - gcry_md_final(c); -- memcpy(md, gcry_md_read(c, 0), MD5_DIGEST_LEN); -+ tmp = gcry_md_read(c, 0); -+ if (tmp == NULL) { -+ gcry_md_close(c); -+ return SSH_ERROR; -+ } -+ memcpy(md, tmp, MD5_DIGEST_LEN); - gcry_md_close(c); -+ return SSH_OK; - } -diff --git a/src/md_mbedcrypto.c b/src/md_mbedcrypto.c -index 227e20ab..b3529b4b 100644 ---- a/src/md_mbedcrypto.c -+++ b/src/md_mbedcrypto.c -@@ -64,27 +64,48 @@ sha1_init(void) - } - - void -+sha1_ctx_free(SHACTX c) -+{ -+ mbedtls_md_free(c); -+ SAFE_FREE(c); -+} -+ -+int - sha1_update(SHACTX c, const void *data, size_t len) - { -- mbedtls_md_update(c, data, len); -+ int rc = mbedtls_md_update(c, data, len); -+ if (rc != 0) { -+ return SSH_ERROR; -+ } -+ return SSH_OK; - } - --void -+int - sha1_final(unsigned char *md, SHACTX c) - { -- mbedtls_md_finish(c, md); -- mbedtls_md_free(c); -- SAFE_FREE(c); -+ int rc = mbedtls_md_finish(c, md); -+ sha1_ctx_free(c); -+ if (rc != 0) { -+ return SSH_ERROR; -+ } -+ return SSH_OK; - } - --void -+int - sha1(const unsigned char *digest, size_t len, unsigned char *hash) - { - const mbedtls_md_info_t *md_info = - mbedtls_md_info_from_type(MBEDTLS_MD_SHA1); -- if (md_info != NULL) { -- mbedtls_md(md_info, digest, len, hash); -+ int rc; -+ -+ if (md_info == NULL) { -+ return SSH_ERROR; -+ } -+ rc = mbedtls_md(md_info, digest, len, hash); -+ if (rc != 0) { -+ return SSH_ERROR; - } -+ return SSH_OK; - } - - SHA256CTX -@@ -122,27 +143,48 @@ sha256_init(void) - } - - void -+sha256_ctx_free(SHA256CTX c) -+{ -+ mbedtls_md_free(c); -+ SAFE_FREE(c); -+} -+ -+int - sha256_update(SHA256CTX c, const void *data, size_t len) - { -- mbedtls_md_update(c, data, len); -+ int rc = mbedtls_md_update(c, data, len); -+ if (rc != 0) { -+ return SSH_ERROR; -+ } -+ return SSH_OK; - } - --void -+int - sha256_final(unsigned char *md, SHA256CTX c) - { -- mbedtls_md_finish(c, md); -+ int rc = mbedtls_md_finish(c, md); - mbedtls_md_free(c); - SAFE_FREE(c); -+ if (rc != 0) { -+ return SSH_ERROR; -+ } -+ return SSH_OK; - } - --void -+int - sha256(const unsigned char *digest, size_t len, unsigned char *hash) - { -+ int rc; - const mbedtls_md_info_t *md_info = - mbedtls_md_info_from_type(MBEDTLS_MD_SHA256); -- if (md_info != NULL) { -- mbedtls_md(md_info, digest, len, hash); -+ if (md_info == NULL) { -+ return SSH_ERROR; -+ } -+ rc = mbedtls_md(md_info, digest, len, hash); -+ if (rc != 0) { -+ return SSH_ERROR; - } -+ return SSH_OK; - } - - SHA384CTX -@@ -180,27 +222,48 @@ sha384_init(void) - } - - void -+sha384_ctx_free(SHA384CTX c) -+{ -+ mbedtls_md_free(c); -+ SAFE_FREE(c); -+} -+ -+int - sha384_update(SHA384CTX c, const void *data, size_t len) - { -- mbedtls_md_update(c, data, len); -+ int rc = mbedtls_md_update(c, data, len); -+ if (rc != 0) { -+ return SSH_ERROR; -+ } -+ return SSH_OK; - } - --void -+int - sha384_final(unsigned char *md, SHA384CTX c) - { -- mbedtls_md_finish(c, md); -- mbedtls_md_free(c); -- SAFE_FREE(c); -+ int rc = mbedtls_md_finish(c, md); -+ sha384_ctx_free(c); -+ if (rc != 0) { -+ return SSH_ERROR; -+ } -+ return SSH_OK; - } - --void -+int - sha384(const unsigned char *digest, size_t len, unsigned char *hash) - { - const mbedtls_md_info_t *md_info = - mbedtls_md_info_from_type(MBEDTLS_MD_SHA384); -- if (md_info != NULL) { -- mbedtls_md(md_info, digest, len, hash); -+ int rc; -+ -+ if (md_info == NULL) { -+ return SSH_ERROR; -+ } -+ rc = mbedtls_md(md_info, digest, len, hash); -+ if (rc != 0) { -+ return SSH_ERROR; - } -+ return SSH_OK; - } - - SHA512CTX -@@ -237,27 +300,48 @@ sha512_init(void) - } - - void -+sha512_ctx_free(SHA512CTX c) -+{ -+ mbedtls_md_free(c); -+ SAFE_FREE(c); -+} -+ -+int - sha512_update(SHA512CTX c, const void *data, size_t len) - { -- mbedtls_md_update(c, data, len); -+ int rc = mbedtls_md_update(c, data, len); -+ if (rc != 0) { -+ return SSH_ERROR; -+ } -+ return SSH_OK; - } - --void -+int - sha512_final(unsigned char *md, SHA512CTX c) - { -- mbedtls_md_finish(c, md); -- mbedtls_md_free(c); -- SAFE_FREE(c); -+ int rc = mbedtls_md_finish(c, md); -+ sha512_ctx_free(c); -+ if (rc != 0) { -+ return SSH_ERROR; -+ } -+ return SSH_OK; - } - --void -+int - sha512(const unsigned char *digest, size_t len, unsigned char *hash) - { - const mbedtls_md_info_t *md_info = - mbedtls_md_info_from_type(MBEDTLS_MD_SHA512); -- if (md_info != NULL) { -- mbedtls_md(md_info, digest, len, hash); -+ int rc; -+ -+ if (md_info == NULL) { -+ return SSH_ERROR; - } -+ rc = mbedtls_md(md_info, digest, len, hash); -+ if (rc != 0) { -+ return SSH_ERROR; -+ } -+ return SSH_OK; - } - - MD5CTX -@@ -294,15 +378,30 @@ md5_init(void) - } - - void -+md5_ctx_free(MD5CTX c) -+{ -+ mbedtls_md_free(c); -+ SAFE_FREE(c); -+} -+ -+int - md5_update(MD5CTX c, const void *data, size_t len) - { -- mbedtls_md_update(c, data, len); -+ int rc = mbedtls_md_update(c, data, len); -+ if (rc != 0) { -+ return SSH_ERROR; -+ } -+ return SSH_OK; - } - --void -+int - md5_final(unsigned char *md, MD5CTX c) - { -- mbedtls_md_finish(c, md); -+ int rc = mbedtls_md_finish(c, md); - mbedtls_md_free(c); - SAFE_FREE(c); -+ if (rc != 0) { -+ return SSH_ERROR; -+ } -+ return SSH_OK; - } -diff --git a/src/session.c b/src/session.c -index fe998dee..8c509699 100644 ---- a/src/session.c -+++ b/src/session.c -@@ -1024,7 +1024,18 @@ int ssh_get_pubkey_hash(ssh_session session, unsigned char **hash) - *hash = NULL; - if (session->current_crypto == NULL || - session->current_crypto->server_pubkey == NULL) { -- ssh_set_error(session,SSH_FATAL,"No current cryptographic context"); -+ ssh_set_error(session, SSH_FATAL, "No current cryptographic context"); -+ return SSH_ERROR; -+ } -+ -+ rc = ssh_get_server_publickey(session, &pubkey); -+ if (rc != SSH_OK) { -+ return SSH_ERROR; -+ } -+ -+ rc = ssh_pki_export_pubkey_blob(pubkey, &pubkey_blob); -+ ssh_key_free(pubkey); -+ if (rc != SSH_OK) { - return SSH_ERROR; - } - -@@ -1039,25 +1050,21 @@ int ssh_get_pubkey_hash(ssh_session session, unsigned char **hash) - return SSH_ERROR; - } - -- rc = ssh_get_server_publickey(session, &pubkey); -+ rc = md5_update(ctx, -+ ssh_string_data(pubkey_blob), -+ ssh_string_len(pubkey_blob)); - if (rc != SSH_OK) { -- md5_final(h, ctx); -+ md5_ctx_free(ctx); - SAFE_FREE(h); -- return SSH_ERROR; -+ return rc; - } -- -- rc = ssh_pki_export_pubkey_blob(pubkey, &pubkey_blob); -- ssh_key_free(pubkey); -+ SSH_STRING_FREE(pubkey_blob); -+ rc = md5_final(h, ctx); - if (rc != SSH_OK) { -- md5_final(h, ctx); - SAFE_FREE(h); -- return SSH_ERROR; -+ return rc; - } - -- md5_update(ctx, ssh_string_data(pubkey_blob), ssh_string_len(pubkey_blob)); -- SSH_STRING_FREE(pubkey_blob); -- md5_final(h, ctx); -- - *hash = h; - - return MD5_DIGEST_LEN; -@@ -1177,8 +1184,17 @@ int ssh_get_publickey_hash(const ssh_key key, - goto out; - } - -- sha1_update(ctx, ssh_string_data(blob), ssh_string_len(blob)); -- sha1_final(h, ctx); -+ rc = sha1_update(ctx, ssh_string_data(blob), ssh_string_len(blob)); -+ if (rc != SSH_OK) { -+ free(h); -+ sha1_ctx_free(ctx); -+ goto out; -+ } -+ rc = sha1_final(h, ctx); -+ if (rc != SSH_OK) { -+ free(h); -+ goto out; -+ } - - *hlen = SHA_DIGEST_LEN; - } -@@ -1200,8 +1216,17 @@ int ssh_get_publickey_hash(const ssh_key key, - goto out; - } - -- sha256_update(ctx, ssh_string_data(blob), ssh_string_len(blob)); -- sha256_final(h, ctx); -+ rc = sha256_update(ctx, ssh_string_data(blob), ssh_string_len(blob)); -+ if (rc != SSH_OK) { -+ free(h); -+ sha256_ctx_free(ctx); -+ goto out; -+ } -+ rc = sha256_final(h, ctx); -+ if (rc != SSH_OK) { -+ free(h); -+ goto out; -+ } - - *hlen = SHA256_DIGEST_LEN; - } -@@ -1231,8 +1256,17 @@ int ssh_get_publickey_hash(const ssh_key key, - goto out; - } - -- md5_update(ctx, ssh_string_data(blob), ssh_string_len(blob)); -- md5_final(h, ctx); -+ rc = md5_update(ctx, ssh_string_data(blob), ssh_string_len(blob)); -+ if (rc != SSH_OK) { -+ free(h); -+ md5_ctx_free(ctx); -+ goto out; -+ } -+ rc = md5_final(h, ctx); -+ if (rc != SSH_OK) { -+ free(h); -+ goto out; -+ } - - *hlen = MD5_DIGEST_LEN; - } --- -2.33.0 - diff --git a/backport-0018-CVE-2023-6918-kdf-Detect-context-init-failures.patch b/backport-0018-CVE-2023-6918-kdf-Detect-context-init-failures.patch deleted file mode 100644 index e1f64f70dcb673cf43e97b65aae24d7e9ea14f2b..0000000000000000000000000000000000000000 --- a/backport-0018-CVE-2023-6918-kdf-Detect-context-init-failures.patch +++ /dev/null @@ -1,54 +0,0 @@ -From 8977e246b6d7ae467cab008a49e0a9e3d84bc2a0 Mon Sep 17 00:00:00 2001 -From: Jakub Jelen -Date: Fri, 15 Dec 2023 13:35:14 +0100 -Subject: [PATCH 18/20] CVE-2023-6918: kdf: Detect context init failures - -Signed-off-by: Jakub Jelen -Reviewed-by: Andreas Schneider ---- - src/kdf.c | 18 +++++++++++++++--- - 1 file changed, 15 insertions(+), 3 deletions(-) - -diff --git a/src/kdf.c b/src/kdf.c -index a8e534e5..6bc477ce 100644 ---- a/src/kdf.c -+++ b/src/kdf.c -@@ -61,20 +61,32 @@ static ssh_mac_ctx ssh_mac_ctx_init(enum ssh_kdf_digest type) - switch (type) { - case SSH_KDF_SHA1: - ctx->ctx.sha1_ctx = sha1_init(); -+ if (ctx->ctx.sha1_ctx == NULL) { -+ goto err; -+ } - return ctx; - case SSH_KDF_SHA256: - ctx->ctx.sha256_ctx = sha256_init(); -+ if (ctx->ctx.sha256_ctx == NULL) { -+ goto err; -+ } - return ctx; - case SSH_KDF_SHA384: - ctx->ctx.sha384_ctx = sha384_init(); -+ if (ctx->ctx.sha384_ctx == NULL) { -+ goto err; -+ } - return ctx; - case SSH_KDF_SHA512: - ctx->ctx.sha512_ctx = sha512_init(); -+ if (ctx->ctx.sha512_ctx == NULL) { -+ goto err; -+ } - return ctx; -- default: -- SAFE_FREE(ctx); -- return NULL; - } -+err: -+ SAFE_FREE(ctx); -+ return NULL; - } - - static void ssh_mac_ctx_free(ssh_mac_ctx ctx) --- -2.33.0 - diff --git a/backport-0019-CVE-2023-6918-tests-Code-coverage-for-ssh_get_pubkey.patch b/backport-0019-CVE-2023-6918-tests-Code-coverage-for-ssh_get_pubkey.patch deleted file mode 100644 index efbd0b2a4e3c419acc1d2c8c44d808645063d262..0000000000000000000000000000000000000000 --- a/backport-0019-CVE-2023-6918-tests-Code-coverage-for-ssh_get_pubkey.patch +++ /dev/null @@ -1,68 +0,0 @@ -From 622421018b58392ffecc29726b947e089b678221 Mon Sep 17 00:00:00 2001 -From: Jakub Jelen -Date: Fri, 15 Dec 2023 15:39:12 +0100 -Subject: [PATCH 19/20] CVE-2023-6918: tests: Code coverage for - ssh_get_pubkey_hash() - -Signed-off-by: Jakub Jelen -Reviewed-by: Andreas Schneider ---- - tests/client/torture_session.c | 35 ++++++++++++++++++++++++++++++++++ - 1 file changed, 35 insertions(+) - -diff --git a/tests/client/torture_session.c b/tests/client/torture_session.c -index 27e8fc86..c437d421 100644 ---- a/tests/client/torture_session.c -+++ b/tests/client/torture_session.c -@@ -391,6 +391,38 @@ static void torture_freed_channel_get_exit_status(void **state) - assert_ssh_return_code_equal(session, rc, SSH_ERROR); - } - -+static void torture_pubkey_hash(void **state) -+{ -+ struct torture_state *s = *state; -+ ssh_session session = s->ssh.session; -+ char *hash = NULL; -+ char *hexa = NULL; -+ int rc = 0; -+ -+ /* bad arguments */ -+ rc = ssh_get_pubkey_hash(session, NULL); -+ assert_int_equal(rc, SSH_ERROR); -+ -+ rc = ssh_get_pubkey_hash(NULL, (unsigned char **)&hash); -+ assert_int_equal(rc, SSH_ERROR); -+ -+ /* deprecated, but should be covered by tests! */ -+ rc = ssh_get_pubkey_hash(session, (unsigned char **)&hash); -+ if (ssh_fips_mode()) { -+ /* When in FIPS mode, expect the call to fail */ -+ assert_int_equal(rc, SSH_ERROR); -+ } else { -+ assert_int_equal(rc, MD5_DIGEST_LEN); -+ -+ hexa = ssh_get_hexa((unsigned char *)hash, rc); -+ SSH_STRING_FREE_CHAR(hash); -+ assert_string_equal(hexa, -+ "ee:80:7f:61:f9:d5:be:f1:96:86:cc:96:7a:db:7a:7b"); -+ -+ SSH_STRING_FREE_CHAR(hexa); -+ } -+} -+ - int torture_run_tests(void) { - int rc; - struct CMUnitTest tests[] = { -@@ -421,6 +453,9 @@ int torture_run_tests(void) { - cmocka_unit_test_setup_teardown(torture_freed_channel_get_exit_status, - session_setup, - session_teardown), -+ cmocka_unit_test_setup_teardown(torture_pubkey_hash, -+ session_setup, -+ session_teardown), - }; - - ssh_init(); --- -2.33.0 - diff --git a/backport-0020-CVE-2025-5318-fix-possible-buffer-overrun.patch b/backport-0020-CVE-2025-5318-fix-possible-buffer-overrun.patch deleted file mode 100644 index 745e7979c8e5bcac26c42242981563f2abc489c8..0000000000000000000000000000000000000000 --- a/backport-0020-CVE-2025-5318-fix-possible-buffer-overrun.patch +++ /dev/null @@ -1,30 +0,0 @@ -From ae8881dfe54214c0c0eb88345c35e15a14081b3d Mon Sep 17 00:00:00 2001 -From: Jakub Jelen -Date: Tue, 22 Apr 2025 21:18:44 +0200 -Subject: CVE-2025-5318: sftpserver: Fix possible buffer overrun - -Signed-off-by: Jakub Jelen -Reviewed-by: Andreas Schneider - -Conflict: NA -Reference:https://git.libssh.org/projects/libssh.git/patch/?id=ae8881dfe54214c0c0eb88345c35e15a14081b3d ---- - src/sftpserver.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/src/sftpserver.c b/src/sftpserver.c -index 9117f15..b3349e1 100644 ---- a/src/sftpserver.c -+++ b/src/sftpserver.c -@@ -538,7 +538,7 @@ void *sftp_handle(sftp_session sftp, ssh_string handle){ - - memcpy(&val, ssh_string_data(handle), sizeof(uint32_t)); - -- if (val > SFTP_HANDLES) { -+ if (val >= SFTP_HANDLES) { - return NULL; - } - --- -2.33.0 - diff --git a/backport-0021-CVE-2025-4877-prevent-integer-overflow-and-potential-OOB.patch b/backport-0021-CVE-2025-4877-prevent-integer-overflow-and-potential-OOB.patch deleted file mode 100644 index bfbda55d9864759656693b6c2258838a67ac5241..0000000000000000000000000000000000000000 --- a/backport-0021-CVE-2025-4877-prevent-integer-overflow-and-potential-OOB.patch +++ /dev/null @@ -1,56 +0,0 @@ -From 00f09acbec55962839fc7837ef14c56fb8fbaf72 Mon Sep 17 00:00:00 2001 -From: Jakub Jelen -Date: Tue, 15 Apr 2025 11:41:24 +0200 -Subject: CVE-2025-4877 base64: Prevent integer overflow and potential -OOB - -Set maximum input to 256MB to have safe margin to the 1GB trigger point -for 32b arch. - -The OOB should not be reachable by any internal code paths as most of -the buffers and strings we use as input for this operation already have -similar limit and none really allows this much of data. - -Signed-off-by: Jakub Jelen -Reviewed-by: Andreas Schneider - -Conflict:NA -Reference:https://git.libssh.org/projects/libssh.git/patch/?id=00f09acbec55962839fc7837ef14c56fb8fbaf72 ---- - src/base64.c | 13 ++++++++++++- - 1 file changed, 12 insertions(+), 1 deletion(-) - -diff --git a/src/base64.c b/src/base64.c -index 4148f49..f42e0e8 100644 ---- a/src/base64.c -+++ b/src/base64.c -@@ -29,6 +29,9 @@ - #include "libssh/priv.h" - #include "libssh/buffer.h" - -+/* Do not allow encoding more than 256MB of data */ -+#define BASE64_MAX_INPUT_LEN 256 * 1024 * 1024 -+ - static - const uint8_t alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "abcdefghijklmnopqrstuvwxyz" -@@ -274,7 +277,15 @@ uint8_t *bin_to_base64(const uint8_t *source, size_t len) - { - uint8_t *base64 = NULL; - uint8_t *ptr = NULL; -- size_t flen = len + (3 - (len % 3)); /* round to upper 3 multiple */ -+ size_t flen = 0; -+ -+ /* Set the artificial upper limit for the input. Otherwise on 32b arch, the -+ * following line could overflow for sizes larger than SIZE_MAX / 4 */ -+ if (len > BASE64_MAX_INPUT_LEN) { -+ return NULL; -+ } -+ -+ flen = len + (3 - (len % 3)); /* round to upper 3 multiple */ - flen = (4 * flen) / 3 + 1; - - base64 = malloc(flen); --- -2.33.0 - diff --git a/backport-0022-CVE-2025-4878-Initialize-pointers-where-posibble.patch b/backport-0022-CVE-2025-4878-Initialize-pointers-where-posibble.patch deleted file mode 100644 index 97425351709e783c597fbd95ca845357cf023033..0000000000000000000000000000000000000000 --- a/backport-0022-CVE-2025-4878-Initialize-pointers-where-posibble.patch +++ /dev/null @@ -1,2602 +0,0 @@ -From 2eb2af4426eb9d473eb131cecea2c81a99d1e2fc Mon Sep 17 00:00:00 2001 -From: Jakub Jelen -Date: Wed, 23 Apr 2025 17:57:11 +0200 -Subject: CVE-2025-4878 Initialize pointers where possible - -This is mostly mechanical change initializing all the pointers I was -able to -find with some grep and manual review of sources and examples. - -Used the following greps (which yield some false positives though): - - git grep " \w* *\* *\w*;$" - git grep " ssh_session \w*;" - git grep " ssh_channel \w*;" - git grep " struct ssh_iterator \*\w*;" - git grep " ssh_bind \w*;" - git grep " ssh_key \w*;" - git grep " ssh_string \w*;" - git grep " ssh_buffer \w*;" - git grep " HMACCTX \w*;" - git grep " SHACTX \w*;" - grep -rinP '^(?!.*=)\s*(?:\w+\s+)*\w+\s*\*\s*\w+\s*;' - -Signed-off-by: Jakub Jelen -Reviewed-by: Andreas Schneider - -Conflict:NA -Reference:https://git.libssh.org/projects/libssh.git/patch/?id=2eb2af4426eb9d473eb131cecea2c81a99d1e2fc ---- - doc/authentication.dox | 10 +++---- - doc/command.dox | 2 +- - doc/forwarding.dox | 4 +-- - doc/guided_tour.dox | 14 ++++----- - doc/shell.dox | 2 +- - examples/authentication.c | 12 ++++---- - examples/connect_ssh.c | 2 +- - examples/exec.c | 4 +-- - examples/knownhosts.c | 2 +- - examples/libssh_scp.c | 11 +++---- - examples/proxy.c | 18 ++++++------ - examples/samplesshd-cb.c | 10 +++---- - examples/samplesshd-kbdint.c | 16 +++++----- - examples/scp_download.c | 4 +-- - examples/senddata.c | 4 +-- - examples/ssh_client.c | 8 ++--- - examples/sshd_direct-tcpip.c | 14 ++++----- - examples/sshnetcat.c | 6 ++-- - src/agent.c | 13 ++++---- - src/auth.c | 7 +++-- - src/bind.c | 11 +++---- - src/bind_config.c | 4 +-- - src/buffer.c | 9 +++--- - src/callbacks.c | 2 +- - src/chachapoly.c | 2 +- - src/channels.c | 57 ++++++++++++++++++------------------ - src/client.c | 2 +- - src/config.c | 4 +-- - src/config_parser.c | 12 ++++---- - src/connect.c | 4 +-- - src/connector.c | 5 ++-- - src/dh_crypto.c | 2 +- - src/ecdh_crypto.c | 8 ++--- - src/ecdh_gcrypt.c | 10 +++---- - src/gcrypt_missing.c | 2 +- - src/getpass.c | 4 +-- - src/gssapi.c | 28 ++++++++++-------- - src/kex.c | 4 +-- - src/known_hosts.c | 41 +++++++++++++------------- - src/knownhosts.c | 18 ++++++------ - src/legacy.c | 43 ++++++++++++++------------- - src/libmbedcrypto.c | 2 +- - src/log.c | 2 +- - src/messages.c | 22 +++++++------- - src/misc.c | 24 +++++++-------- - src/options.c | 22 +++++++------- - src/packet.c | 6 ++-- - src/packet_crypt.c | 2 +- - src/pki.c | 48 +++++++++++++++--------------- - src/pki_container_openssh.c | 16 +++++----- - src/pki_crypto.c | 8 ++--- - src/pki_ed25519.c | 6 ++-- - src/pki_ed25519_common.c | 2 +- - src/pki_gcrypt.c | 14 ++++----- - src/pki_mbedcrypto.c | 12 ++++---- - src/poll.c | 10 +++---- - src/server.c | 23 ++++++++------- - src/session.c | 14 ++++----- - src/sftpserver.c | 12 ++++---- - src/string.c | 4 +-- - src/threads/winlocks.c | 2 +- - src/wrapper.c | 2 +- - 62 files changed, 352 insertions(+), 336 deletions(-) - -diff --git a/doc/authentication.dox b/doc/authentication.dox -index 7d0ab81..a0b2df8 100644 ---- a/doc/authentication.dox -+++ b/doc/authentication.dox -@@ -105,7 +105,7 @@ Here is a small example of password authentication: - @code - int authenticate_password(ssh_session session) - { -- char *password; -+ char *password = NULL; - int rc; - - password = getpass("Enter your password: "); -@@ -218,7 +218,7 @@ int authenticate_kbdint(ssh_session session) - rc = ssh_userauth_kbdint(session, NULL, NULL); - while (rc == SSH_AUTH_INFO) - { -- const char *name, *instruction; -+ const char *name = NULL, *instruction = NULL; - int nprompts, iprompt; - - name = ssh_userauth_kbdint_getname(session); -@@ -231,7 +231,7 @@ int authenticate_kbdint(ssh_session session) - printf("%s\n", instruction); - for (iprompt = 0; iprompt < nprompts; iprompt++) - { -- const char *prompt; -+ const char *prompt = NULL; - char echo; - - prompt = ssh_userauth_kbdint_getprompt(session, iprompt, &echo); -@@ -251,7 +251,7 @@ int authenticate_kbdint(ssh_session session) - } - else - { -- char *ptr; -+ char *ptr = NULL; - - ptr = getpass(prompt); - if (ssh_userauth_kbdint_setanswer(session, iprompt, ptr) < 0) -@@ -354,7 +354,7 @@ The following example shows how to retrieve and dispose the issue banner: - int display_banner(ssh_session session) - { - int rc; -- char *banner; -+ char *banner = NULL; - - /* - *** Does not work without calling ssh_userauth_none() first *** -diff --git a/doc/command.dox b/doc/command.dox -index 588151c..e82748c 100644 ---- a/doc/command.dox -+++ b/doc/command.dox -@@ -22,7 +22,7 @@ a SSH session that uses this channel: - @code - int show_remote_files(ssh_session session) - { -- ssh_channel channel; -+ ssh_channel channel = NULL; - int rc; - - channel = ssh_channel_new(session); -diff --git a/doc/forwarding.dox b/doc/forwarding.dox -index 2b202b4..3ca3aa8 100644 ---- a/doc/forwarding.dox -+++ b/doc/forwarding.dox -@@ -100,7 +100,7 @@ used to retrieve google's home page from the remote SSH server. - @code - int direct_forwarding(ssh_session session) - { -- ssh_channel forwarding_channel; -+ ssh_channel forwarding_channel = NULL; - int rc = SSH_ERROR; - char *http_get = "GET / HTTP/1.1\nHost: www.google.com\n\n"; - int nbytes, nwritten; -@@ -161,7 +161,7 @@ local libssh application, which handles them: - int web_server(ssh_session session) - { - int rc; -- ssh_channel channel; -+ ssh_channel channel = NULL; - char buffer[256]; - int nbytes, nwritten; - int port = 0; -diff --git a/doc/guided_tour.dox b/doc/guided_tour.dox -index 69576f1..60f4087 100644 ---- a/doc/guided_tour.dox -+++ b/doc/guided_tour.dox -@@ -79,7 +79,7 @@ Here is a small example of how to use it: - - int main() - { -- ssh_session my_ssh_session; -+ ssh_session my_ssh_session = NULL; - int verbosity = SSH_LOG_PROTOCOL; - int port = 22; - -@@ -126,7 +126,7 @@ Here's an example: - - int main() - { -- ssh_session my_ssh_session; -+ ssh_session my_ssh_session = NULL; - int rc; - - my_ssh_session = ssh_new(); -@@ -190,8 +190,8 @@ int verify_knownhost(ssh_session session) - ssh_key srv_pubkey = NULL; - size_t hlen; - char buf[10]; -- char *hexa; -- char *p; -+ char *hexa = NULL; -+ char *p = NULL; - int cmp; - int rc; - -@@ -317,9 +317,9 @@ The example below shows an authentication with password: - - int main() - { -- ssh_session my_ssh_session; -+ ssh_session my_ssh_session = NULL; - int rc; -- char *password; -+ char *password = NULL; - - // Open session and set options - my_ssh_session = ssh_new(); -@@ -380,7 +380,7 @@ The example below shows how to execute a remote command: - @code - int show_remote_processes(ssh_session session) - { -- ssh_channel channel; -+ ssh_channel channel = NULL; - int rc; - char buffer[256]; - int nbytes; -diff --git a/doc/shell.dox b/doc/shell.dox -index d770f27..54d9788 100644 ---- a/doc/shell.dox -+++ b/doc/shell.dox -@@ -26,7 +26,7 @@ The code sample below achieves these tasks: - @code - int shell_session(ssh_session session) - { -- ssh_channel channel; -+ ssh_channel channel = NULL; - int rc; - - channel = ssh_channel_new(session); -diff --git a/examples/authentication.c b/examples/authentication.c -index 7c47c8b..31de7cf 100644 ---- a/examples/authentication.c -+++ b/examples/authentication.c -@@ -30,8 +30,8 @@ int authenticate_kbdint(ssh_session session, const char *password) - - err = ssh_userauth_kbdint(session, NULL, NULL); - while (err == SSH_AUTH_INFO) { -- const char *instruction; -- const char *name; -+ const char *instruction = NULL; -+ const char *name = NULL; - char buffer[128]; - int i, n; - -@@ -48,8 +48,8 @@ int authenticate_kbdint(ssh_session session, const char *password) - } - - for (i = 0; i < n; i++) { -- const char *answer; -- const char *prompt; -+ const char *answer = NULL; -+ const char *prompt = NULL; - char echo; - - prompt = ssh_userauth_kbdint_getprompt(session, i, &echo); -@@ -58,7 +58,7 @@ int authenticate_kbdint(ssh_session session, const char *password) - } - - if (echo) { -- char *p; -+ char *p = NULL; - - printf("%s", prompt); - -@@ -143,7 +143,7 @@ int authenticate_console(ssh_session session) - int rc; - int method; - char password[128] = {0}; -- char *banner; -+ char *banner = NULL; - - // Try to authenticate - rc = ssh_userauth_none(session, NULL); -diff --git a/examples/connect_ssh.c b/examples/connect_ssh.c -index c9e4ef6..0609427 100644 ---- a/examples/connect_ssh.c -+++ b/examples/connect_ssh.c -@@ -22,7 +22,7 @@ clients must be made or how a client should react. - #include - - ssh_session connect_ssh(const char *host, const char *user,int verbosity){ -- ssh_session session; -+ ssh_session session = NULL; - int auth=0; - - session=ssh_new(); -diff --git a/examples/exec.c b/examples/exec.c -index 77d3be4..f90df36 100644 ---- a/examples/exec.c -+++ b/examples/exec.c -@@ -5,8 +5,8 @@ - #include "examples_common.h" - - int main(void) { -- ssh_session session; -- ssh_channel channel; -+ ssh_session session = NULL; -+ ssh_channel channel = NULL; - char buffer[256]; - int rbytes, wbytes, total = 0; - int rc; -diff --git a/examples/knownhosts.c b/examples/knownhosts.c -index 0726bfa..2857a08 100644 ---- a/examples/knownhosts.c -+++ b/examples/knownhosts.c -@@ -38,7 +38,7 @@ int verify_knownhost(ssh_session session) - char buf[10]; - unsigned char *hash = NULL; - size_t hlen; -- ssh_key srv_pubkey; -+ ssh_key srv_pubkey = NULL; - int rc; - - rc = ssh_get_server_publickey(session, &srv_pubkey); -diff --git a/examples/libssh_scp.c b/examples/libssh_scp.c -index 6fdf8a4..a332e0d 100644 ---- a/examples/libssh_scp.c -+++ b/examples/libssh_scp.c -@@ -26,9 +26,9 @@ program. - #define BUF_SIZE 16384 - #endif - --static char **sources; -+static char **sources = NULL; - static int nsources; --static char *destination; -+static char *destination = NULL; - static int verbosity = 0; - - struct location { -@@ -114,9 +114,10 @@ static void location_free(struct location *loc) - } - } - --static struct location *parse_location(char *loc) { -- struct location *location; -- char *ptr; -+static struct location *parse_location(char *loc) -+{ -+ struct location *location = NULL; -+ char *ptr = NULL; - - location = malloc(sizeof(struct location)); - if (location == NULL) { -diff --git a/examples/proxy.c b/examples/proxy.c -index 159a37e..2545178 100644 ---- a/examples/proxy.c -+++ b/examples/proxy.c -@@ -35,8 +35,8 @@ clients must be made or how a client should react. - static int authenticated=0; - static int tries = 0; - static int error = 0; --static ssh_channel chan=NULL; --static char *username; -+static ssh_channel chan = NULL; -+static char *username = NULL; - static ssh_gssapi_creds client_creds = NULL; - - static int auth_password(ssh_session session, const char *user, -@@ -216,11 +216,12 @@ static error_t parse_opt (int key, char *arg, struct argp_state *state) { - static struct argp argp = {options, parse_opt, args_doc, doc, NULL, NULL, NULL}; - #endif /* HAVE_ARGP_H */ - --int main(int argc, char **argv){ -- ssh_session session; -- ssh_bind sshbind; -- ssh_event mainloop; -- ssh_session client_session; -+int main(int argc, char **argv) -+{ -+ ssh_session session = NULL; -+ ssh_bind sshbind = NULL; -+ ssh_event mainloop = NULL; -+ ssh_session client_session = NULL; - - struct ssh_server_callbacks_struct cb = { - .userdata = NULL, -@@ -231,7 +232,7 @@ int main(int argc, char **argv){ - - char buf[BUF_SIZE]; - char host[128]=""; -- char *ptr; -+ char *ptr = NULL; - int i,r, rc; - - sshbind=ssh_bind_new(); -@@ -348,4 +349,3 @@ int main(int argc, char **argv){ - ssh_finalize(); - return 0; - } -- -diff --git a/examples/samplesshd-cb.c b/examples/samplesshd-cb.c -index e5b4899..693b040 100644 ---- a/examples/samplesshd-cb.c -+++ b/examples/samplesshd-cb.c -@@ -257,10 +257,11 @@ static error_t parse_opt (int key, char *arg, struct argp_state *state) { - static struct argp argp = {options, parse_opt, args_doc, doc, NULL, NULL, NULL}; - #endif /* HAVE_ARGP_H */ - --int main(int argc, char **argv){ -- ssh_session session; -- ssh_bind sshbind; -- ssh_event mainloop; -+int main(int argc, char **argv) -+{ -+ ssh_session session = NULL; -+ ssh_bind sshbind = NULL; -+ ssh_event mainloop = NULL; - struct ssh_server_callbacks_struct cb = { - .userdata = NULL, - .auth_none_function = auth_none, -@@ -353,4 +354,3 @@ int main(int argc, char **argv){ - ssh_finalize(); - return 0; - } -- -diff --git a/examples/samplesshd-kbdint.c b/examples/samplesshd-kbdint.c -index 6608306..141088c 100644 ---- a/examples/samplesshd-kbdint.c -+++ b/examples/samplesshd-kbdint.c -@@ -187,8 +187,8 @@ static error_t parse_opt (int key, char *arg, struct argp_state *state) { - static struct argp argp = {options, parse_opt, args_doc, doc, NULL, NULL, NULL}; - #endif /* HAVE_ARGP_H */ - --static const char *name; --static const char *instruction; -+static const char *name = NULL; -+static const char *instruction = NULL; - static const char *prompts[2]; - static char echo[] = { 1, 0 }; - -@@ -292,11 +292,12 @@ static int authenticate(ssh_session session) { - return 0; - } - --int main(int argc, char **argv){ -- ssh_session session; -- ssh_bind sshbind; -- ssh_message message; -- ssh_channel chan=0; -+int main(int argc, char **argv) -+{ -+ ssh_session session = NULL; -+ ssh_bind sshbind = NULL; -+ ssh_message message = NULL; -+ ssh_channel chan = NULL; - char buf[BUF_SIZE]; - int auth=0; - int shell=0; -@@ -426,4 +427,3 @@ int main(int argc, char **argv){ - ssh_finalize(); - return 0; - } -- -diff --git a/examples/scp_download.c b/examples/scp_download.c -index e6c1e79..dcaa2cb 100644 ---- a/examples/scp_download.c -+++ b/examples/scp_download.c -@@ -108,7 +108,7 @@ static int fetch_files(ssh_session session){ - int size; - char buffer[BUF_SIZE]; - int mode; -- char *filename; -+ char *filename = NULL; - int r; - ssh_scp scp=ssh_scp_new(session, SSH_SCP_READ | SSH_SCP_RECURSIVE, "/tmp/libssh_tests/*"); - if(ssh_scp_init(scp) != SSH_OK){ -@@ -167,7 +167,7 @@ static int fetch_files(ssh_session session){ - } - - int main(int argc, char **argv){ -- ssh_session session; -+ ssh_session session = NULL; - if(opts(argc,argv)<0) - return EXIT_FAILURE; - session=connect_ssh(host,NULL,verbosity); -diff --git a/examples/senddata.c b/examples/senddata.c -index 21181fb..6dc8bbb 100644 ---- a/examples/senddata.c -+++ b/examples/senddata.c -@@ -6,8 +6,8 @@ - #define LIMIT 0x100000000UL - - int main(void) { -- ssh_session session; -- ssh_channel channel; -+ ssh_session session = NULL; -+ ssh_channel channel = NULL; - char buffer[1024*1024]; - int rc; - uint64_t total=0; -diff --git a/examples/ssh_client.c b/examples/ssh_client.c -index aaf0cb5..896890c 100644 ---- a/examples/ssh_client.c -+++ b/examples/ssh_client.c -@@ -53,7 +53,7 @@ static struct termios terminal; - - static char *pcap_file = NULL; - --static char *proxycommand; -+static char *proxycommand = NULL; - - static int auth_callback(const char *prompt, - char *buf, -@@ -252,7 +252,7 @@ static void select_loop(ssh_session session,ssh_channel channel) - - static void shell(ssh_session session) - { -- ssh_channel channel; -+ ssh_channel channel = NULL; - struct termios terminal_local; - int interactive=isatty(0); - -@@ -324,7 +324,7 @@ static void batch_shell(ssh_session session) - static int client(ssh_session session) - { - int auth = 0; -- char *banner; -+ char *banner = NULL; - int state; - - if (user) { -@@ -408,7 +408,7 @@ static void cleanup_pcap(void) - - int main(int argc, char **argv) - { -- ssh_session session; -+ ssh_session session = NULL; - - ssh_init(); - session = ssh_new(); -diff --git a/examples/sshd_direct-tcpip.c b/examples/sshd_direct-tcpip.c -index b0e2979..152377e 100644 ---- a/examples/sshd_direct-tcpip.c -+++ b/examples/sshd_direct-tcpip.c -@@ -358,7 +358,7 @@ my_fd_data_function(UNUSED_PARAM(socket_t fd), - { - struct event_fd_data_struct *event_fd_data = (struct event_fd_data_struct *)userdata; - ssh_channel channel = event_fd_data->channel; -- ssh_session session; -+ ssh_session session = NULL; - int len, i, wr; - char buf[BUF_SIZE]; - int blocking; -@@ -452,8 +452,8 @@ open_tcp_socket(ssh_message msg) - { - struct sockaddr_in sin; - int forwardsock = -1; -- struct hostent *host; -- const char *dest_hostname; -+ struct hostent *host = NULL; -+ const char *dest_hostname = NULL; - int dest_port; - - forwardsock = socket(AF_INET, SOCK_STREAM, 0); -@@ -496,8 +496,8 @@ message_callback(UNUSED_PARAM(ssh_session session), - UNUSED_PARAM(void *userdata)) - { - ssh_channel channel; -- int socket_fd, *pFd; -- struct ssh_channel_callbacks_struct *cb_chan; -+ int socket_fd, *pFd = NULL; -+ struct ssh_channel_callbacks_struct *cb_chan = NULL; - struct event_fd_data_struct *event_fd_data; - - _ssh_log(SSH_LOG_PACKET, "=== message_callback", "Message type: %d", -@@ -665,8 +665,8 @@ static struct argp argp = {options, parse_opt, args_doc, doc, NULL, NULL, NULL}; - int - main(int argc, char **argv) - { -- ssh_session session; -- ssh_bind sshbind; -+ ssh_session session = NULL; -+ ssh_bind sshbind = NULL; - struct ssh_server_callbacks_struct cb = { - .userdata = NULL, - .auth_password_function = auth_password, -diff --git a/examples/sshnetcat.c b/examples/sshnetcat.c -index 59b0a28..8a1153a 100644 ---- a/examples/sshnetcat.c -+++ b/examples/sshnetcat.c -@@ -39,7 +39,7 @@ clients must be made or how a client should react. - #define BUF_SIZE 4096 - #endif - --char *host; -+char *host = NULL; - const char *desthost="localhost"; - const char *port="22"; - -@@ -193,7 +193,7 @@ static void forwarding(ssh_session session){ - - static int client(ssh_session session){ - int auth=0; -- char *banner; -+ char *banner = NULL; - int state; - - if (ssh_options_set(session, SSH_OPTIONS_HOST ,host) < 0) -@@ -246,7 +246,7 @@ void cleanup_pcap(void) - #endif - - int main(int argc, char **argv){ -- ssh_session session; -+ ssh_session session = NULL; - - session = ssh_new(); - -diff --git a/src/agent.c b/src/agent.c -index 6e3d7d7..c81b080 100644 ---- a/src/agent.c -+++ b/src/agent.c -@@ -424,8 +424,9 @@ ssh_key ssh_agent_get_first_ident(struct ssh_session_struct *session, - - /* caller has to free comment */ - ssh_key ssh_agent_get_next_ident(struct ssh_session_struct *session, -- char **comment) { -- struct ssh_key_struct *key; -+ char **comment) -+{ -+ struct ssh_key_struct *key = NULL; - struct ssh_string_struct *blob = NULL; - struct ssh_string_struct *tmp = NULL; - int rc; -@@ -494,10 +495,10 @@ ssh_string ssh_agent_sign_data(ssh_session session, - const ssh_key pubkey, - struct ssh_buffer_struct *data) - { -- ssh_buffer request; -- ssh_buffer reply; -- ssh_string key_blob; -- ssh_string sig_blob; -+ ssh_buffer request = NULL; -+ ssh_buffer reply = NULL; -+ ssh_string key_blob = NULL; -+ ssh_string sig_blob = NULL; - unsigned int type = 0; - unsigned int flags = 0; - uint32_t dlen; -diff --git a/src/auth.c b/src/auth.c -index 4feb655..9802231 100644 ---- a/src/auth.c -+++ b/src/auth.c -@@ -195,8 +195,9 @@ static int ssh_userauth_get_response(ssh_session session) - * - * This banner should be shown to user prior to authentication - */ --SSH_PACKET_CALLBACK(ssh_packet_userauth_banner) { -- ssh_string banner; -+SSH_PACKET_CALLBACK(ssh_packet_userauth_banner) -+{ -+ ssh_string banner = NULL; - (void)type; - (void)user; - -@@ -1398,7 +1399,7 @@ int ssh_userauth_agent_pubkey(ssh_session session, - const char *username, - ssh_public_key publickey) - { -- ssh_key key; -+ ssh_key key = NULL; - int rc; - - key = ssh_key_new(); -diff --git a/src/bind.c b/src/bind.c -index a91e674..c331006 100644 ---- a/src/bind.c -+++ b/src/bind.c -@@ -74,7 +74,7 @@ - static socket_t bind_socket(ssh_bind sshbind, const char *hostname, - int port) { - char port_c[6]; -- struct addrinfo *ai; -+ struct addrinfo *ai = NULL; - struct addrinfo hints; - int opt = 1; - socket_t s; -@@ -132,8 +132,9 @@ static socket_t bind_socket(ssh_bind sshbind, const char *hostname, - return s; - } - --ssh_bind ssh_bind_new(void) { -- ssh_bind ptr; -+ssh_bind ssh_bind_new(void) -+{ -+ ssh_bind ptr = NULL; - - ptr = calloc(1, sizeof(struct ssh_bind_struct)); - if (ptr == NULL) { -@@ -251,7 +252,7 @@ static int ssh_bind_import_keys(ssh_bind sshbind) { - } - - int ssh_bind_listen(ssh_bind sshbind) { -- const char *host; -+ const char *host = NULL; - socket_t fd; - int rc; - -@@ -475,7 +476,7 @@ int ssh_bind_accept_fd(ssh_bind sshbind, ssh_session session, socket_t fd) - return SSH_ERROR; - } - } else { -- char *p; -+ char *p = NULL; - /* If something was set to the session prior to calling this - * function, keep only what is allowed by the options set in - * sshbind */ -diff --git a/src/bind_config.c b/src/bind_config.c -index 27c42c9..ed42cbe 100644 ---- a/src/bind_config.c -+++ b/src/bind_config.c -@@ -200,7 +200,7 @@ local_parse_file(ssh_bind bind, - uint8_t *seen, - unsigned int depth) - { -- FILE *f; -+ FILE *f = NULL; - char line[MAX_LINE_SIZE] = {0}; - unsigned int count = 0; - int rv; -@@ -626,7 +626,7 @@ int ssh_bind_config_parse_file(ssh_bind bind, const char *filename) - { - char line[MAX_LINE_SIZE] = {0}; - unsigned int count = 0; -- FILE *f; -+ FILE *f = NULL; - uint32_t parser_flags; - int rv; - -diff --git a/src/buffer.c b/src/buffer.c -index 8991e00..62fda33 100644 ---- a/src/buffer.c -+++ b/src/buffer.c -@@ -371,7 +371,8 @@ int ssh_buffer_allocate_size(struct ssh_buffer_struct *buffer, - */ - void *ssh_buffer_allocate(struct ssh_buffer_struct *buffer, uint32_t len) - { -- void *ptr; -+ void *ptr = NULL; -+ - buffer_verify(buffer); - - if (buffer->used + len < len) { -@@ -925,7 +926,7 @@ int ssh_buffer_pack_va(struct ssh_buffer_struct *buffer, - va_list ap) - { - int rc = SSH_ERROR; -- const char *p; -+ const char *p = NULL; - union { - uint8_t byte; - uint16_t word; -@@ -934,7 +935,7 @@ int ssh_buffer_pack_va(struct ssh_buffer_struct *buffer, - ssh_string string; - void *data; - } o; -- char *cstring; -+ char *cstring = NULL; - bignum b; - size_t len; - size_t count; -@@ -1093,7 +1094,7 @@ int ssh_buffer_unpack_va(struct ssh_buffer_struct *buffer, - va_list ap) - { - int rc = SSH_ERROR; -- const char *p = format, *last; -+ const char *p = format, *last = NULL; - union { - uint8_t *byte; - uint16_t *word; -diff --git a/src/callbacks.c b/src/callbacks.c -index 3ed2f11..6bfed62 100644 ---- a/src/callbacks.c -+++ b/src/callbacks.c -@@ -113,7 +113,7 @@ int ssh_add_channel_callbacks(ssh_channel channel, ssh_channel_callbacks cb) - - int ssh_remove_channel_callbacks(ssh_channel channel, ssh_channel_callbacks cb) - { -- struct ssh_iterator *it; -+ struct ssh_iterator *it = NULL; - - if (channel == NULL || channel->callbacks == NULL){ - return SSH_ERROR; -diff --git a/src/chachapoly.c b/src/chachapoly.c -index 2cd2385..354a0d2 100644 ---- a/src/chachapoly.c -+++ b/src/chachapoly.c -@@ -42,7 +42,7 @@ static int chacha20_set_encrypt_key(struct ssh_cipher_struct *cipher, - void *key, - void *IV) - { -- struct chacha20_poly1305_keysched *sched; -+ struct chacha20_poly1305_keysched *sched = NULL; - uint8_t *u8key = key; - (void)IV; - -diff --git a/src/channels.c b/src/channels.c -index f2fe39a..459246b 100644 ---- a/src/channels.c -+++ b/src/channels.c -@@ -165,7 +165,7 @@ uint32_t ssh_channel_new_id(ssh_session session) - */ - SSH_PACKET_CALLBACK(ssh_packet_channel_open_conf){ - uint32_t channelid=0; -- ssh_channel channel; -+ ssh_channel channel = NULL; - int rc; - (void)type; - (void)user; -@@ -226,7 +226,7 @@ error: - */ - SSH_PACKET_CALLBACK(ssh_packet_channel_open_fail){ - -- ssh_channel channel; -+ ssh_channel channel = NULL; - char *error = NULL; - uint32_t code; - int rc; -@@ -386,7 +386,7 @@ end: - /* return channel with corresponding local id, or NULL if not found */ - ssh_channel ssh_channel_from_local(ssh_session session, uint32_t id) { - struct ssh_iterator *it; -- ssh_channel channel; -+ ssh_channel channel = NULL; - - for (it = ssh_list_get_iterator(session->channels); it != NULL ; it=it->next) { - channel = ssh_iterator_value(ssh_channel, it); -@@ -471,7 +471,7 @@ error: - */ - static ssh_channel channel_from_msg(ssh_session session, ssh_buffer packet) - { -- ssh_channel channel; -+ ssh_channel channel = NULL; - uint32_t chan; - int rc; - -@@ -493,7 +493,7 @@ static ssh_channel channel_from_msg(ssh_session session, ssh_buffer packet) - } - - SSH_PACKET_CALLBACK(channel_rcv_change_window) { -- ssh_channel channel; -+ ssh_channel channel = NULL; - uint32_t bytes; - int rc; - (void)user; -@@ -632,7 +632,7 @@ SSH_PACKET_CALLBACK(channel_rcv_data){ - } - - SSH_PACKET_CALLBACK(channel_rcv_eof) { -- ssh_channel channel; -+ ssh_channel channel = NULL; - (void)user; - (void)type; - -@@ -676,8 +676,9 @@ static bool ssh_channel_has_unread_data(ssh_channel channel) - return false; - } - --SSH_PACKET_CALLBACK(channel_rcv_close) { -- ssh_channel channel; -+SSH_PACKET_CALLBACK(channel_rcv_close) -+{ -+ ssh_channel channel = NULL; - (void)user; - (void)type; - -@@ -902,7 +903,7 @@ int channel_default_bufferize(ssh_channel channel, - void *data, uint32_t len, - bool is_stderr) - { -- ssh_session session; -+ ssh_session session = NULL; - - if(channel == NULL) { - return -1; -@@ -1041,7 +1042,7 @@ int ssh_channel_open_auth_agent(ssh_channel channel) - int ssh_channel_open_forward(ssh_channel channel, const char *remotehost, - int remoteport, const char *sourcehost, int localport) - { -- ssh_session session; -+ ssh_session session = NULL; - ssh_buffer payload = NULL; - ssh_string str = NULL; - int rc = SSH_ERROR; -@@ -1179,7 +1180,7 @@ error: - */ - void ssh_channel_free(ssh_channel channel) - { -- ssh_session session; -+ ssh_session session = NULL; - - if (channel == NULL) { - return; -@@ -1280,7 +1281,7 @@ void ssh_channel_do_free(ssh_channel channel) - */ - int ssh_channel_send_eof(ssh_channel channel) - { -- ssh_session session; -+ ssh_session session = NULL; - int rc = SSH_ERROR; - int err; - -@@ -1341,7 +1342,7 @@ error: - */ - int ssh_channel_close(ssh_channel channel) - { -- ssh_session session; -+ ssh_session session = NULL; - int rc = 0; - - if(channel == NULL) { -@@ -1437,7 +1438,7 @@ static int channel_write_common(ssh_channel channel, - const void *data, - uint32_t len, int is_stderr) - { -- ssh_session session; -+ ssh_session session = NULL; - uint32_t origlen = len; - size_t effectivelen; - size_t maxpacketlen; -@@ -1694,7 +1695,7 @@ void ssh_channel_set_blocking(ssh_channel channel, int blocking) - * @brief handle a SSH_CHANNEL_SUCCESS packet and set the channel state. - */ - SSH_PACKET_CALLBACK(ssh_packet_channel_success){ -- ssh_channel channel; -+ ssh_channel channel = NULL; - (void)type; - (void)user; - -@@ -1724,7 +1725,7 @@ SSH_PACKET_CALLBACK(ssh_packet_channel_success){ - * @brief Handle a SSH_CHANNEL_FAILURE packet and set the channel state. - */ - SSH_PACKET_CALLBACK(ssh_packet_channel_failure){ -- ssh_channel channel; -+ ssh_channel channel = NULL; - (void)type; - (void)user; - -@@ -1863,7 +1864,7 @@ error: - int ssh_channel_request_pty_size(ssh_channel channel, const char *terminal, - int col, int row) - { -- ssh_session session; -+ ssh_session session = NULL; - ssh_buffer buffer = NULL; - int rc = SSH_ERROR; - -@@ -2174,7 +2175,7 @@ static ssh_channel ssh_channel_accept(ssh_session session, int channeltype, - #endif - ssh_message msg = NULL; - ssh_channel channel = NULL; -- struct ssh_iterator *iterator; -+ struct ssh_iterator *iterator = NULL; - int t; - - /* -@@ -2838,7 +2839,7 @@ error: - int channel_read_buffer(ssh_channel channel, ssh_buffer buffer, uint32_t count, - int is_stderr) - { -- ssh_session session; -+ ssh_session session = NULL; - char *buffer_tmp = NULL; - int r; - uint32_t total=0; -@@ -2979,8 +2980,8 @@ int ssh_channel_read_timeout(ssh_channel channel, - int is_stderr, - int timeout_ms) - { -- ssh_session session; -- ssh_buffer stdbuf; -+ ssh_session session = NULL; -+ ssh_buffer stdbuf = NULL; - uint32_t len; - struct ssh_channel_read_termination_struct ctx; - int rc; -@@ -3103,7 +3104,7 @@ int ssh_channel_read_nonblocking(ssh_channel channel, - uint32_t count, - int is_stderr) - { -- ssh_session session; -+ ssh_session session = NULL; - uint32_t to_read; - int rc; - int blocking; -@@ -3213,8 +3214,8 @@ int ssh_channel_poll(ssh_channel channel, int is_stderr) - */ - int ssh_channel_poll_timeout(ssh_channel channel, int timeout, int is_stderr) - { -- ssh_session session; -- ssh_buffer stdbuf; -+ ssh_session session = NULL; -+ ssh_buffer stdbuf = NULL; - struct ssh_channel_read_termination_struct ctx; - size_t len; - int rc; -@@ -3341,7 +3342,7 @@ channel_protocol_select(ssh_channel *rchans, ssh_channel *wchans, - ssh_channel *echans, ssh_channel *rout, - ssh_channel *wout, ssh_channel *eout) - { -- ssh_channel chan; -+ ssh_channel chan = NULL; - int i; - int j = 0; - -@@ -3422,7 +3423,7 @@ static size_t count_ptrs(ssh_channel *ptrs) - int ssh_channel_select(ssh_channel *readchans, ssh_channel *writechans, - ssh_channel *exceptchans, struct timeval * timeout) - { -- ssh_channel *rchans, *wchans, *echans; -+ ssh_channel *rchans = NULL, *wchans = NULL, *echans = NULL; - ssh_channel dummy = NULL; - ssh_event event = NULL; - int rc; -@@ -3609,7 +3610,7 @@ int ssh_channel_write_stderr(ssh_channel channel, const void *data, uint32_t len - int ssh_channel_open_reverse_forward(ssh_channel channel, const char *remotehost, - int remoteport, const char *sourcehost, int localport) - { -- ssh_session session; -+ ssh_session session = NULL; - ssh_buffer payload = NULL; - int rc = SSH_ERROR; - -@@ -3673,7 +3674,7 @@ error: - int ssh_channel_open_x11(ssh_channel channel, - const char *orig_addr, int orig_port) - { -- ssh_session session; -+ ssh_session session = NULL; - ssh_buffer payload = NULL; - int rc = SSH_ERROR; - -diff --git a/src/client.c b/src/client.c -index e912090..0cfca1c 100644 ---- a/src/client.c -+++ b/src/client.c -@@ -748,7 +748,7 @@ ssh_session_set_disconnect_message(ssh_session session, const char *message) - void - ssh_disconnect(ssh_session session) - { -- struct ssh_iterator *it; -+ struct ssh_iterator *it = NULL; - int rc; - - if (session == NULL) { -diff --git a/src/config.c b/src/config.c -index 273db7c..7447d64 100644 ---- a/src/config.c -+++ b/src/config.c -@@ -203,7 +203,7 @@ local_parse_file(ssh_session session, - unsigned int depth, - bool global) - { -- FILE *f; -+ FILE *f = NULL; - char line[MAX_LINE_SIZE] = {0}; - unsigned int count = 0; - int rv; -@@ -1201,7 +1201,7 @@ int ssh_config_parse_file(ssh_session session, const char *filename) - { - char line[MAX_LINE_SIZE] = {0}; - unsigned int count = 0; -- FILE *f; -+ FILE *f = NULL; - int parsing, rv; - bool global = 0; - -diff --git a/src/config_parser.c b/src/config_parser.c -index d4b2d2c..56374d9 100644 ---- a/src/config_parser.c -+++ b/src/config_parser.c -@@ -39,8 +39,8 @@ - */ - char *ssh_config_get_cmd(char **str) - { -- register char *c; -- char *r; -+ register char *c = NULL; -+ char *r = NULL; - - /* Ignore leading spaces */ - for (c = *str; *c; c++) { -@@ -67,7 +67,7 @@ out: - */ - char *ssh_config_get_token(char **str) - { -- register char *c; -+ register char *c = NULL; - bool had_equal = false; - char *r = NULL; - -@@ -116,7 +116,7 @@ out: - - long ssh_config_get_long(char **str, long notfound) - { -- char *p, *endp; -+ char *p = NULL, *endp = NULL; - long i; - - p = ssh_config_get_token(str); -@@ -133,7 +133,7 @@ long ssh_config_get_long(char **str, long notfound) - - const char *ssh_config_get_str_tok(char **str, const char *def) - { -- char *p; -+ char *p = NULL; - - p = ssh_config_get_token(str); - if (p && *p) { -@@ -145,7 +145,7 @@ const char *ssh_config_get_str_tok(char **str, const char *def) - - int ssh_config_get_yesno(char **str, int notfound) - { -- const char *p; -+ const char *p = NULL; - - p = ssh_config_get_str_tok(str, NULL); - if (p == NULL) { -diff --git a/src/connect.c b/src/connect.c -index 15cae64..2d09af5 100644 ---- a/src/connect.c -+++ b/src/connect.c -@@ -194,8 +194,8 @@ socket_t ssh_connect_host_nonblocking(ssh_session session, const char *host, - } - - if (bind_addr) { -- struct addrinfo *bind_ai; -- struct addrinfo *bind_itr; -+ struct addrinfo *bind_ai = NULL; -+ struct addrinfo *bind_itr = NULL; - - SSH_LOG(SSH_LOG_PACKET, "Resolving %s", bind_addr); - -diff --git a/src/connector.c b/src/connector.c -index 5671674..6632cca 100644 ---- a/src/connector.c -+++ b/src/connector.c -@@ -637,8 +637,9 @@ error: - return rc; - } - --int ssh_connector_remove_event(ssh_connector connector) { -- ssh_session session; -+int ssh_connector_remove_event(ssh_connector connector) -+{ -+ ssh_session session = NULL; - - if (connector->in_poll != NULL) { - ssh_event_remove_poll(connector->event, connector->in_poll); -diff --git a/src/dh_crypto.c b/src/dh_crypto.c -index 9ff7ad3..4dd9b50 100644 ---- a/src/dh_crypto.c -+++ b/src/dh_crypto.c -@@ -404,7 +404,7 @@ done: - */ - int ssh_dh_init_common(struct ssh_crypto_struct *crypto) - { -- struct dh_ctx *ctx; -+ struct dh_ctx *ctx = NULL; - int rc; - - ctx = calloc(1, sizeof(*ctx)); -diff --git a/src/ecdh_crypto.c b/src/ecdh_crypto.c -index 069b137..b674b2e 100644 ---- a/src/ecdh_crypto.c -+++ b/src/ecdh_crypto.c -@@ -415,14 +415,14 @@ int ecdh_build_k(ssh_session session) { - */ - SSH_PACKET_CALLBACK(ssh_packet_server_ecdh_init){ - /* ECDH keys */ -- ssh_string q_c_string; -- ssh_string q_s_string; -+ ssh_string q_c_string = NULL; -+ ssh_string q_s_string = NULL; - /* TODO Change to new API when the OpenSSL will support export of uncompressed EC keys - * https://github.com/openssl/openssl/pull/16624 - * #if OPENSSL_VERSION_NUMBER < 0x30000000L - */ - #if 1 -- EC_KEY *ecdh_key; -+ EC_KEY *ecdh_key = NULL; - const EC_GROUP *group; - const EC_POINT *ecdh_pubkey; - bignum_CTX ctx; -@@ -437,7 +437,7 @@ SSH_PACKET_CALLBACK(ssh_packet_server_ecdh_init){ - const char *curve = NULL; - #endif /* OPENSSL_VERSION_NUMBER */ - /* SSH host keys (rsa,dsa,ecdsa) */ -- ssh_key privkey; -+ ssh_key privkey = NULL; - enum ssh_digest_e digest = SSH_DIGEST_AUTO; - ssh_string sig_blob = NULL; - ssh_string pubkey_blob = NULL; -diff --git a/src/ecdh_gcrypt.c b/src/ecdh_gcrypt.c -index 3d9d426..a8a8c37 100644 ---- a/src/ecdh_gcrypt.c -+++ b/src/ecdh_gcrypt.c -@@ -132,9 +132,9 @@ int ecdh_build_k(ssh_session session) - #else - size_t k_len = 0; - enum ssh_key_exchange_e kex_type = session->next_crypto->kex_type; -- ssh_string s; -+ ssh_string s = NULL; - #endif -- ssh_string pubkey_raw; -+ ssh_string pubkey_raw = NULL; - gcry_sexp_t pubkey = NULL; - ssh_string privkey = NULL; - int rc = SSH_ERROR; -@@ -267,12 +267,12 @@ int ecdh_build_k(ssh_session session) - SSH_PACKET_CALLBACK(ssh_packet_server_ecdh_init){ - gpg_error_t err; - /* ECDH keys */ -- ssh_string q_c_string; -- ssh_string q_s_string; -+ ssh_string q_c_string = NULL; -+ ssh_string q_s_string = NULL; - gcry_sexp_t param = NULL; - gcry_sexp_t key = NULL; - /* SSH host keys (rsa,dsa,ecdsa) */ -- ssh_key privkey; -+ ssh_key privkey = NULL; - enum ssh_digest_e digest = SSH_DIGEST_AUTO; - ssh_string sig_blob = NULL; - ssh_string pubkey_blob = NULL; -diff --git a/src/gcrypt_missing.c b/src/gcrypt_missing.c -index e931ec5..56dcfb6 100644 ---- a/src/gcrypt_missing.c -+++ b/src/gcrypt_missing.c -@@ -47,7 +47,7 @@ int ssh_gcry_dec2bn(bignum *bn, const char *data) { - - char *ssh_gcry_bn2dec(bignum bn) { - bignum bndup, num, ten; -- char *ret; -+ char *ret = NULL; - int count, count2; - int size, rsize; - char decnum; -diff --git a/src/getpass.c b/src/getpass.c -index 6be33c7..c19c4bc 100644 ---- a/src/getpass.c -+++ b/src/getpass.c -@@ -46,7 +46,7 @@ - */ - static int ssh_gets(const char *prompt, char *buf, size_t len, int verify) - { -- char *tmp; -+ char *tmp = NULL; - char *ptr = NULL; - int ok = 0; - -@@ -78,7 +78,7 @@ static int ssh_gets(const char *prompt, char *buf, size_t len, int verify) - } - - if (verify) { -- char *key_string; -+ char *key_string = NULL; - - key_string = calloc(1, len); - if (key_string == NULL) { -diff --git a/src/gssapi.c b/src/gssapi.c -index 5325ac7..fd7b25a 100644 ---- a/src/gssapi.c -+++ b/src/gssapi.c -@@ -196,7 +196,7 @@ ssh_gssapi_handle_userauth(ssh_session session, const char *user, - gss_name_t server_name; /* local server fqdn */ - OM_uint32 maj_stat, min_stat; - size_t i; -- char *ptr; -+ char *ptr = NULL; - gss_OID_set supported; /* oids supported by server */ - gss_OID_set both_supported; /* oids supported by both client and server */ - gss_OID_set selected; /* oid selected for authentication */ -@@ -341,7 +341,7 @@ static char *ssh_gssapi_name_to_char(gss_name_t name) - { - gss_buffer_desc buffer; - OM_uint32 maj_stat, min_stat; -- char *ptr; -+ char *ptr = NULL; - maj_stat = gss_display_name(&min_stat, name, &buffer, NULL); - ssh_gssapi_log_error(SSH_LOG_WARNING, - "converting name", -@@ -359,9 +359,10 @@ static char *ssh_gssapi_name_to_char(gss_name_t name) - - } - --SSH_PACKET_CALLBACK(ssh_packet_userauth_gssapi_token_server){ -- ssh_string token; -- char *hexa; -+SSH_PACKET_CALLBACK(ssh_packet_userauth_gssapi_token_server) -+{ -+ ssh_string token = NULL; -+ char *hexa = NULL; - OM_uint32 maj_stat, min_stat; - gss_buffer_desc input_token, output_token = GSS_C_EMPTY_BUFFER; - gss_name_t client_name = GSS_C_NO_NAME; -@@ -385,7 +386,7 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_gssapi_token_server){ - } - - if (ssh_callbacks_exists(session->server_callbacks, gssapi_accept_sec_ctx_function)){ -- ssh_string out_token=NULL; -+ ssh_string out_token = NULL; - rc = session->server_callbacks->gssapi_accept_sec_ctx_function(session, - token, &out_token, session->server_callbacks->userdata); - if (rc == SSH_ERROR){ -@@ -507,7 +508,7 @@ static ssh_buffer ssh_gssapi_build_mic(ssh_session session) - - SSH_PACKET_CALLBACK(ssh_packet_userauth_gssapi_mic) - { -- ssh_string mic_token; -+ ssh_string mic_token = NULL; - OM_uint32 maj_stat, min_stat; - gss_buffer_desc mic_buf = GSS_C_EMPTY_BUFFER; - gss_buffer_desc mic_token_buf = GSS_C_EMPTY_BUFFER; -@@ -670,7 +671,7 @@ static int ssh_gssapi_match(ssh_session session, gss_OID_set *valid_oids) - gss_name_t client_id = GSS_C_NO_NAME; - gss_OID oid; - unsigned int i; -- char *ptr; -+ char *ptr = NULL; - int ret; - - if (session->gssapi->client.client_deleg_creds == NULL) { -@@ -866,11 +867,11 @@ static gss_OID ssh_gssapi_oid_from_string(ssh_string oid_s) - - SSH_PACKET_CALLBACK(ssh_packet_userauth_gssapi_response){ - int rc; -- ssh_string oid_s; -+ ssh_string oid_s = NULL; - gss_uint32 maj_stat, min_stat; - gss_buffer_desc input_token = GSS_C_EMPTY_BUFFER; - gss_buffer_desc output_token = GSS_C_EMPTY_BUFFER; -- char *hexa; -+ char *hexa = NULL; - (void)type; - (void)user; - -@@ -987,10 +988,11 @@ static int ssh_gssapi_send_mic(ssh_session session) - return ssh_packet_send(session); - } - --SSH_PACKET_CALLBACK(ssh_packet_userauth_gssapi_token_client){ -+SSH_PACKET_CALLBACK(ssh_packet_userauth_gssapi_token_client) -+{ - int rc; -- ssh_string token; -- char *hexa; -+ ssh_string token = NULL; -+ char *hexa = NULL; - OM_uint32 maj_stat, min_stat; - gss_buffer_desc input_token, output_token = GSS_C_EMPTY_BUFFER; - (void)user; -diff --git a/src/kex.c b/src/kex.c -index fbc70cf..ecfc012 100644 ---- a/src/kex.c -+++ b/src/kex.c -@@ -330,7 +330,7 @@ static int cmp_first_kex_algo(const char *client_str, - size_t client_kex_len; - size_t server_kex_len; - -- char *colon; -+ char *colon = NULL; - - int is_wrong = 1; - -@@ -762,7 +762,7 @@ char *ssh_client_select_hostkeys(ssh_session session) - int ssh_set_client_kex(ssh_session session) - { - struct ssh_kex_struct *client = &session->next_crypto->client_kex; -- const char *wanted; -+ const char *wanted = NULL; - int ok; - int i; - -diff --git a/src/known_hosts.c b/src/known_hosts.c -index 84e1557..f660a6f 100644 ---- a/src/known_hosts.c -+++ b/src/known_hosts.c -@@ -79,8 +79,8 @@ static struct ssh_tokens_st *ssh_get_knownhost_line(FILE **file, - const char **found_type) - { - char buffer[MAX_LINE_SIZE] = {0}; -- char *ptr; -- struct ssh_tokens_st *tokens; -+ char *ptr = NULL; -+ struct ssh_tokens_st *tokens = NULL; - - if (*file == NULL) { - *file = fopen(filename,"r"); -@@ -149,7 +149,7 @@ static struct ssh_tokens_st *ssh_get_knownhost_line(FILE **file, - static int check_public_key(ssh_session session, char **tokens) { - ssh_string pubkey_blob = NULL; - ssh_buffer pubkey_buffer; -- char *pubkey_64; -+ char *pubkey_64 = NULL; - int rc; - - /* ssh-dss or ssh-rsa */ -@@ -205,11 +205,11 @@ static int match_hashed_host(const char *host, const char *sourcehash) - * hash := HMAC_SHA1(key=salt,data=host) - */ - unsigned char buffer[256] = {0}; -- ssh_buffer salt; -- ssh_buffer hash; -- HMACCTX mac; -- char *source; -- char *b64hash; -+ ssh_buffer salt = NULL; -+ ssh_buffer hash = NULL; -+ HMACCTX mac = NULL; -+ char *source = NULL; -+ char *b64hash = NULL; - int match, rc; - size_t size; - -@@ -304,14 +304,14 @@ static int match_hashed_host(const char *host, const char *sourcehash) - int ssh_is_server_known(ssh_session session) - { - FILE *file = NULL; -- char *host; -- char *hostport; -- const char *type; -+ char *host = NULL; -+ char *hostport = NULL; -+ const char *type = NULL; - int match; - int i = 0; -- char *files[3]; -+ char *files[3] = {0}; - -- struct ssh_tokens_st *tokens; -+ struct ssh_tokens_st *tokens = NULL; - - int ret = SSH_SERVER_NOT_KNOWN; - -@@ -443,12 +443,13 @@ int ssh_is_server_known(ssh_session session) - * @deprecated Please use ssh_session_export_known_hosts_entry() - * @brief This function is deprecated. - */ --char * ssh_dump_knownhost(ssh_session session) { -+char *ssh_dump_knownhost(ssh_session session) -+{ - ssh_key server_pubkey = NULL; -- char *host; -- char *hostport; -- char *buffer; -- char *b64_key; -+ char *host = NULL; -+ char *hostport = NULL; -+ char *buffer = NULL; -+ char *b64_key = NULL; - int rc; - - if (session->opts.host == NULL) { -@@ -513,9 +514,9 @@ char * ssh_dump_knownhost(ssh_session session) { - */ - int ssh_write_knownhost(ssh_session session) - { -- FILE *file; -+ FILE *file = NULL; - char *buffer = NULL; -- char *dir; -+ char *dir = NULL; - int rc; - - if (session->opts.knownhosts == NULL) { -diff --git a/src/knownhosts.c b/src/knownhosts.c -index 9f97809..109b4f0 100644 ---- a/src/knownhosts.c -+++ b/src/knownhosts.c -@@ -61,7 +61,7 @@ static int hash_hostname(const char *name, - size_t *hash_size) - { - int rc; -- HMACCTX mac_ctx; -+ HMACCTX mac_ctx = NULL; - - mac_ctx = hmac_init(salt, salt_size, SSH_HMAC_SHA1); - if (mac_ctx == NULL) { -@@ -81,8 +81,8 @@ static int hash_hostname(const char *name, - - static int match_hashed_hostname(const char *host, const char *hashed_host) - { -- char *hashed; -- char *b64_hash; -+ char *hashed = NULL; -+ char *b64_hash = NULL; - ssh_buffer salt = NULL; - ssh_buffer hash = NULL; - unsigned char hashed_buf[256] = {0}; -@@ -229,7 +229,7 @@ static int ssh_known_hosts_read_entries(const char *match, - char line[MAX_LINE_SIZE]; - size_t lineno = 0; - size_t len = 0; -- FILE *fp; -+ FILE *fp = NULL; - int rc; - - fp = fopen(filename, "r"); -@@ -288,7 +288,7 @@ static int ssh_known_hosts_read_entries(const char *match, - for (it = ssh_list_get_iterator(*entries); - it != NULL; - it = it->next) { -- struct ssh_knownhosts_entry *entry2; -+ struct ssh_knownhosts_entry *entry2 = NULL; - int cmp; - entry2 = ssh_iterator_value(struct ssh_knownhosts_entry *, it); - cmp = ssh_known_hosts_entries_compare(entry, entry2); -@@ -312,8 +312,8 @@ error: - - static char *ssh_session_get_host_port(ssh_session session) - { -- char *host_port; -- char *host; -+ char *host_port = NULL; -+ char *host = NULL; - - if (session->opts.host == NULL) { - ssh_set_error(session, -@@ -537,7 +537,7 @@ char *ssh_known_hosts_get_algorithms_names(ssh_session session) - char *host_port = NULL; - size_t count; - bool needcomma = false; -- char *names; -+ char *names = NULL; - - int rc; - -@@ -645,7 +645,7 @@ int ssh_known_hosts_parse_line(const char *hostname, - { - struct ssh_knownhosts_entry *e = NULL; - char *known_host = NULL; -- char *p; -+ char *p = NULL; - char *save_tok = NULL; - enum ssh_keytypes_e key_type; - int match = 0; -diff --git a/src/legacy.c b/src/legacy.c -index 7b165db..7359040 100644 ---- a/src/legacy.c -+++ b/src/legacy.c -@@ -48,7 +48,7 @@ int ssh_auth_list(ssh_session session) { - int ssh_userauth_offer_pubkey(ssh_session session, const char *username, - int type, ssh_string publickey) - { -- ssh_key key; -+ ssh_key key = NULL; - int rc; - - (void) type; /* unused */ -@@ -70,7 +70,7 @@ int ssh_userauth_pubkey(ssh_session session, - ssh_string publickey, - ssh_private_key privatekey) - { -- ssh_key key; -+ ssh_key key = NULL; - int rc; - - (void) publickey; /* unused */ -@@ -389,10 +389,11 @@ void publickey_free(ssh_public_key key) { - SAFE_FREE(key); - } - --ssh_public_key publickey_from_privatekey(ssh_private_key prv) { -- struct ssh_public_key_struct *p; -- ssh_key privkey; -- ssh_key pubkey; -+ssh_public_key publickey_from_privatekey(ssh_private_key prv) -+{ -+ struct ssh_public_key_struct *p = NULL; -+ ssh_key privkey = NULL; -+ ssh_key pubkey = NULL; - int rc; - - privkey = ssh_key_new(); -@@ -434,8 +435,8 @@ ssh_private_key privatekey_from_file(ssh_session session, - const char *passphrase) { - ssh_auth_callback auth_fn = NULL; - void *auth_data = NULL; -- ssh_private_key privkey; -- ssh_key key; -+ ssh_private_key privkey = NULL; -+ ssh_key key = NULL; - int rc; - - (void) type; /* unused */ -@@ -510,7 +511,7 @@ void privatekey_free(ssh_private_key prv) { - - ssh_string publickey_from_file(ssh_session session, const char *filename, - int *type) { -- ssh_key key; -+ ssh_key key = NULL; - ssh_string key_str = NULL; - int rc; - -@@ -543,9 +544,10 @@ int ssh_type_from_name(const char *name) { - return ssh_key_type_from_name(name); - } - --ssh_public_key publickey_from_string(ssh_session session, ssh_string pubkey_s) { -- struct ssh_public_key_struct *pubkey; -- ssh_key key; -+ssh_public_key publickey_from_string(ssh_session session, ssh_string pubkey_s) -+{ -+ struct ssh_public_key_struct *pubkey = NULL; -+ ssh_key key = NULL; - int rc; - - (void) session; /* unused */ -@@ -579,9 +581,10 @@ ssh_public_key publickey_from_string(ssh_session session, ssh_string pubkey_s) { - return pubkey; - } - --ssh_string publickey_to_string(ssh_public_key pubkey) { -- ssh_key key; -- ssh_string key_blob; -+ssh_string publickey_to_string(ssh_public_key pubkey) -+{ -+ ssh_key key = NULL; -+ ssh_string key_blob = NULL; - int rc; - - if (pubkey == NULL) { -@@ -624,11 +627,11 @@ int ssh_publickey_to_file(ssh_session session, - ssh_string pubkey, - int type) - { -- FILE *fp; -- char *user; -+ FILE *fp = NULL; -+ char *user = NULL; - char buffer[1024]; - char host[256]; -- unsigned char *pubkey_64; -+ unsigned char *pubkey_64 = NULL; - size_t len; - int rc; - if(session==NULL) -@@ -695,9 +698,9 @@ int ssh_try_publickey_from_file(ssh_session session, - const char *keyfile, - ssh_string *publickey, - int *type) { -- char *pubkey_file; -+ char *pubkey_file = NULL; - size_t len; -- ssh_string pubkey_string; -+ ssh_string pubkey_string = NULL; - int pubkey_type; - - if (session == NULL || keyfile == NULL || publickey == NULL || type == NULL) { -diff --git a/src/libmbedcrypto.c b/src/libmbedcrypto.c -index caa3b6e..422d5ae 100644 ---- a/src/libmbedcrypto.c -+++ b/src/libmbedcrypto.c -@@ -133,7 +133,7 @@ cipher_init(struct ssh_cipher_struct *cipher, - void *IV) - { - const mbedtls_cipher_info_t *cipher_info = NULL; -- mbedtls_cipher_context_t *ctx; -+ mbedtls_cipher_context_t *ctx = NULL; - size_t key_bitlen = 0; - size_t iv_size = 0; - int rc; -diff --git a/src/log.c b/src/log.c -index 5bae18b..fabbe94 100644 ---- a/src/log.c -+++ b/src/log.c -@@ -44,7 +44,7 @@ - - static LIBSSH_THREAD int ssh_log_level; - static LIBSSH_THREAD ssh_logging_callback ssh_log_cb; --static LIBSSH_THREAD void *ssh_log_userdata; -+static LIBSSH_THREAD void *ssh_log_userdata = NULL; - - /** - * @defgroup libssh_log The SSH logging functions -diff --git a/src/messages.c b/src/messages.c -index 3f96953..54497fa 100644 ---- a/src/messages.c -+++ b/src/messages.c -@@ -478,8 +478,8 @@ static void ssh_message_queue(ssh_session session, ssh_message message) - * @returns The head message or NULL if it doesn't exist. - */ - ssh_message ssh_message_pop_head(ssh_session session){ -- ssh_message msg=NULL; -- struct ssh_iterator *i; -+ ssh_message msg = NULL; -+ struct ssh_iterator *i = NULL; - if(session->ssh_message_list == NULL) - return NULL; - i=ssh_list_get_iterator(session->ssh_message_list); -@@ -493,7 +493,7 @@ ssh_message ssh_message_pop_head(ssh_session session){ - /* Returns 1 if there is a message available */ - static int ssh_message_termination(void *s){ - ssh_session session = s; -- struct ssh_iterator *it; -+ struct ssh_iterator *it = NULL; - if(session->session_state == SSH_SESSION_STATE_ERROR) - return 1; - it = ssh_list_get_iterator(session->ssh_message_list); -@@ -694,8 +694,8 @@ static ssh_buffer ssh_msg_userauth_build_digest(ssh_session session, - ssh_string algo) - { - struct ssh_crypto_struct *crypto = NULL; -- ssh_buffer buffer; -- ssh_string str=NULL; -+ ssh_buffer buffer = NULL; -+ ssh_string str = NULL; - int rc; - - crypto = ssh_packet_get_current_crypto(session, SSH_DIRECTION_IN); -@@ -933,9 +933,9 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_request){ - #ifdef WITH_GSSAPI - if (strcmp(method, "gssapi-with-mic") == 0) { - uint32_t n_oid; -- ssh_string *oids; -- ssh_string oid; -- char *hexa; -+ ssh_string *oids = NULL; -+ ssh_string oid = NULL; -+ char *hexa = NULL; - int i; - ssh_buffer_get_u32(packet, &n_oid); - n_oid=ntohl(n_oid); -@@ -1019,7 +1019,7 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_info_response){ - SSH_PACKET_CALLBACK(ssh_packet_userauth_info_response){ - uint32_t nanswers; - uint32_t i; -- ssh_string tmp; -+ ssh_string tmp = NULL; - int rc; - - ssh_message msg = NULL; -@@ -1251,7 +1251,7 @@ end: - * @returns SSH_OK on success, SSH_ERROR if an error occurred. - */ - int ssh_message_channel_request_open_reply_accept_channel(ssh_message msg, ssh_channel chan) { -- ssh_session session; -+ ssh_session session = NULL; - int rc; - - if (msg == NULL) { -@@ -1302,7 +1302,7 @@ int ssh_message_channel_request_open_reply_accept_channel(ssh_message msg, ssh_c - * @returns NULL in case of error - */ - ssh_channel ssh_message_channel_request_open_reply_accept(ssh_message msg) { -- ssh_channel chan; -+ ssh_channel chan = NULL; - int rc; - - if (msg == NULL) { -diff --git a/src/misc.c b/src/misc.c -index 7081f12..f371f33 100644 ---- a/src/misc.c -+++ b/src/misc.c -@@ -393,7 +393,7 @@ int ssh_is_ipaddr(const char *str) - - char *ssh_lowercase(const char* str) - { -- char *new, *p; -+ char *new = NULL, *p = NULL; - - if (str == NULL) { - return NULL; -@@ -447,7 +447,7 @@ char *ssh_hostport(const char *host, int port) - char *ssh_get_hexa(const unsigned char *what, size_t len) - { - const char h[] = "0123456789abcdef"; -- char *hexa; -+ char *hexa = NULL; - size_t i; - size_t hlen = len * 3; - -@@ -716,7 +716,7 @@ struct ssh_list *ssh_list_new(void) - - void ssh_list_free(struct ssh_list *list) - { -- struct ssh_iterator *ptr, *next; -+ struct ssh_iterator *ptr = NULL, *next = NULL; - if (!list) - return; - ptr = list->root; -@@ -737,7 +737,7 @@ struct ssh_iterator *ssh_list_get_iterator(const struct ssh_list *list) - - struct ssh_iterator *ssh_list_find(const struct ssh_list *list, void *value) - { -- struct ssh_iterator *it; -+ struct ssh_iterator *it = NULL; - - for (it = ssh_list_get_iterator(list); it != NULL ; it = it->next) - if (it->data == value) -@@ -826,7 +826,7 @@ int ssh_list_prepend(struct ssh_list *list, const void *data) - - void ssh_list_remove(struct ssh_list *list, struct ssh_iterator *iterator) - { -- struct ssh_iterator *ptr, *prev; -+ struct ssh_iterator *ptr = NULL, *prev = NULL; - - if (list == NULL) { - return; -@@ -967,7 +967,7 @@ char *ssh_dirname (const char *path) - char *ssh_basename (const char *path) - { - char *new = NULL; -- const char *s; -+ const char *s = NULL; - size_t len; - - if (path == NULL || *path == '\0') { -@@ -1105,8 +1105,8 @@ int ssh_mkdirs(const char *pathname, mode_t mode) - */ - char *ssh_path_expand_tilde(const char *d) - { -- char *h = NULL, *r; -- const char *p; -+ char *h = NULL, *r = NULL; -+ const char *p = NULL; - size_t ld; - size_t lh = 0; - -@@ -1121,7 +1121,7 @@ char *ssh_path_expand_tilde(const char *d) - #ifdef _WIN32 - return strdup(d); - #else -- struct passwd *pw; -+ struct passwd *pw = NULL; - size_t s = p - d; - char u[128]; - -@@ -1182,7 +1182,7 @@ char *ssh_path_expand_escape(ssh_session session, const char *s) - char *buf = NULL; - char *r = NULL; - char *x = NULL; -- const char *p; -+ const char *p = NULL; - size_t i, l; - - r = ssh_path_expand_tilde(s); -@@ -1335,8 +1335,8 @@ char *ssh_path_expand_escape(ssh_session session, const char *s) - */ - int ssh_analyze_banner(ssh_session session, int server) - { -- const char *banner; -- const char *openssh; -+ const char *banner = NULL; -+ const char *openssh = NULL; - - if (server) { - banner = session->clientbanner; -diff --git a/src/options.c b/src/options.c -index b3ecffe..9ff0436 100644 ---- a/src/options.c -+++ b/src/options.c -@@ -67,7 +67,7 @@ - */ - int ssh_options_copy(ssh_session src, ssh_session *dest) - { -- ssh_session new; -+ ssh_session new = NULL; - struct ssh_iterator *it = NULL; - struct ssh_list *list = NULL; - char *id = NULL; -@@ -499,8 +499,8 @@ int ssh_options_set_algo(ssh_session session, - int ssh_options_set(ssh_session session, enum ssh_options_e type, - const void *value) - { -- const char *v; -- char *p, *q; -+ const char *v = NULL; -+ char *p = NULL, *q = NULL; - long int i; - unsigned int u; - int rc; -@@ -1164,7 +1164,7 @@ int ssh_options_get_port(ssh_session session, unsigned int* port_target) { - */ - int ssh_options_get(ssh_session session, enum ssh_options_e type, char** value) - { -- char* src = NULL; -+ char *src = NULL; - - if (session == NULL) { - return SSH_ERROR; -@@ -1186,7 +1186,7 @@ int ssh_options_get(ssh_session session, enum ssh_options_e type, char** value) - break; - } - case SSH_OPTIONS_IDENTITY: { -- struct ssh_iterator *it; -+ struct ssh_iterator *it = NULL; - it = ssh_list_get_iterator(session->opts.identity); - if (it == NULL) { - it = ssh_list_get_iterator(session->opts.identity_non_exp); -@@ -1439,7 +1439,7 @@ int ssh_options_getopt(ssh_session session, int *argcptr, char **argv) - */ - int ssh_options_parse_config(ssh_session session, const char *filename) - { -- char *expanded_filename; -+ char *expanded_filename = NULL; - int r; - - if (session == NULL) { -@@ -1485,7 +1485,7 @@ out: - - int ssh_options_apply(ssh_session session) - { -- char *tmp; -+ char *tmp = NULL; - int rc; - - if (session->opts.sshdir == NULL) { -@@ -1795,8 +1795,8 @@ int ssh_bind_options_set(ssh_bind sshbind, enum ssh_bind_options_e type, - const void *value) - { - bool allowed; -- char *p, *q; -- const char *v; -+ char *p = NULL, *q = NULL; -+ const char *v = NULL; - int i, rc; - - if (sshbind == NULL) { -@@ -2198,7 +2198,7 @@ static char *ssh_bind_options_expand_escape(ssh_bind sshbind, const char *s) - char *buf = NULL; - char *r = NULL; - char *x = NULL; -- const char *p; -+ const char *p = NULL; - size_t i, l; - - r = ssh_path_expand_tilde(s); -@@ -2304,7 +2304,7 @@ static char *ssh_bind_options_expand_escape(ssh_bind sshbind, const char *s) - int ssh_bind_options_parse_config(ssh_bind sshbind, const char *filename) - { - int rc = 0; -- char *expanded_filename; -+ char *expanded_filename = NULL; - - if (sshbind == NULL) { - return -1; -diff --git a/src/packet.c b/src/packet.c -index ea73f9a..4b4d0dc 100644 ---- a/src/packet.c -+++ b/src/packet.c -@@ -1430,8 +1430,8 @@ error: - static void ssh_packet_socket_controlflow_callback(int code, void *userdata) - { - ssh_session session = userdata; -- struct ssh_iterator *it; -- ssh_channel channel; -+ struct ssh_iterator *it = NULL; -+ ssh_channel channel = NULL; - - if (code == SSH_SOCKET_FLOW_WRITEWONTBLOCK) { - SSH_LOG(SSH_LOG_TRACE, "sending channel_write_wontblock callback"); -@@ -1894,7 +1894,7 @@ int ssh_packet_send(ssh_session session) - - /* We finished the key exchange so we can try to send our queue now */ - if (rc == SSH_OK && type == SSH2_MSG_NEWKEYS) { -- struct ssh_iterator *it; -+ struct ssh_iterator *it = NULL; - - if (session->flags & SSH_SESSION_FLAG_KEX_STRICT) { - /* reset packet sequence number when running in strict kex mode */ -diff --git a/src/packet_crypt.c b/src/packet_crypt.c -index fe3f489..96e9586 100644 ---- a/src/packet_crypt.c -+++ b/src/packet_crypt.c -@@ -262,7 +262,7 @@ int ssh_packet_hmac_verify(ssh_session session, - { - struct ssh_crypto_struct *crypto = NULL; - unsigned char hmacbuf[DIGEST_MAX_LEN] = {0}; -- HMACCTX ctx; -+ HMACCTX ctx = NULL; - size_t hmaclen = DIGEST_MAX_LEN; - uint32_t seq; - int cmp; -diff --git a/src/pki.c b/src/pki.c -index a7c84c5..33fc508 100644 ---- a/src/pki.c -+++ b/src/pki.c -@@ -369,7 +369,7 @@ enum ssh_digest_e ssh_key_hash_from_name(const char *name) - */ - int ssh_key_algorithm_allowed(ssh_session session, const char *type) - { -- const char *allowed_list; -+ const char *allowed_list = NULL; - - if (session->client) { - allowed_list = session->opts.pubkey_accepted_types; -@@ -729,7 +729,7 @@ int ssh_key_cmp(const ssh_key k1, - - ssh_signature ssh_signature_new(void) - { -- struct ssh_signature_struct *sig; -+ struct ssh_signature_struct *sig = NULL; - - sig = malloc(sizeof(struct ssh_signature_struct)); - if (sig == NULL) { -@@ -821,7 +821,7 @@ int ssh_pki_import_privkey_base64(const char *b64_key, - void *auth_data, - ssh_key *pkey) - { -- ssh_key key; -+ ssh_key key = NULL; - char *openssh_header = NULL; - - if (b64_key == NULL || pkey == NULL) { -@@ -944,8 +944,8 @@ int ssh_pki_import_privkey_file(const char *filename, - void *auth_data, - ssh_key *pkey) { - struct stat sb; -- char *key_buf; -- FILE *file; -+ char *key_buf = NULL; -+ FILE *file = NULL; - off_t size; - int rc; - char err_msg[SSH_ERRNO_MSG_MAX] = {0}; -@@ -1093,8 +1093,8 @@ int ssh_pki_export_privkey_file(const ssh_key privkey, - /* temporary function to migrate seamlessly to ssh_key */ - ssh_public_key ssh_pki_convert_key_to_publickey(const ssh_key key) - { -- ssh_public_key pub; -- ssh_key tmp; -+ ssh_public_key pub = NULL; -+ ssh_key tmp = NULL; - - if (key == NULL) { - return NULL; -@@ -1131,7 +1131,7 @@ ssh_public_key ssh_pki_convert_key_to_publickey(const ssh_key key) - - ssh_private_key ssh_pki_convert_key_to_privatekey(const ssh_key key) - { -- ssh_private_key privkey; -+ ssh_private_key privkey = NULL; - - privkey = calloc(1, sizeof(struct ssh_private_key_struct)); - if (privkey == NULL) { -@@ -1521,9 +1521,9 @@ static int pki_import_cert_buffer(ssh_buffer buffer, - enum ssh_keytypes_e type, - ssh_key *pkey) - { -- ssh_buffer cert; -- ssh_string tmp_s; -- const char *type_c; -+ ssh_buffer cert = NULL; -+ ssh_string tmp_s = NULL; -+ const char *type_c = NULL; - ssh_key key = NULL; - int rc; - -@@ -2067,7 +2067,7 @@ error: - int ssh_pki_export_privkey_to_pubkey(const ssh_key privkey, - ssh_key *pkey) - { -- ssh_key pubkey; -+ ssh_key pubkey = NULL; - - if (privkey == NULL || !ssh_key_is_private(privkey)) { - return SSH_ERROR; -@@ -2105,7 +2105,7 @@ int ssh_pki_export_privkey_to_pubkey(const ssh_key privkey, - int ssh_pki_export_pubkey_blob(const ssh_key key, - ssh_string *pblob) - { -- ssh_string blob; -+ ssh_string blob = NULL; - - if (key == NULL) { - return SSH_OK; -@@ -2135,8 +2135,8 @@ int ssh_pki_export_pubkey_blob(const ssh_key key, - int ssh_pki_export_pubkey_base64(const ssh_key key, - char **b64_key) - { -- ssh_string key_blob; -- unsigned char *b64; -+ ssh_string key_blob = NULL; -+ unsigned char *b64 = NULL; - - if (key == NULL || b64_key == NULL) { - return SSH_ERROR; -@@ -2175,9 +2175,9 @@ int ssh_pki_export_pubkey_file(const ssh_key key, - { - char key_buf[MAX_LINE_SIZE]; - char host[256]; -- char *b64_key; -- char *user; -- FILE *fp; -+ char *b64_key = NULL; -+ char *user = NULL; -+ FILE *fp = NULL; - int rc; - - if (key == NULL || filename == NULL || *filename == '\0') { -@@ -2238,7 +2238,7 @@ int ssh_pki_export_pubkey_file(const ssh_key key, - * @returns SSH_OK on success, SSH_ERROR otherwise. - **/ - int ssh_pki_copy_cert_to_privkey(const ssh_key certkey, ssh_key privkey) { -- ssh_buffer cert_buffer; -+ ssh_buffer cert_buffer = NULL; - int rc; - - if (certkey == NULL || privkey == NULL) { -@@ -2273,7 +2273,7 @@ int ssh_pki_export_signature_blob(const ssh_signature sig, - ssh_string *sig_blob) - { - ssh_buffer buf = NULL; -- ssh_string str; -+ ssh_string str = NULL; - int rc; - - if (sig == NULL || sig_blob == NULL) { -@@ -2337,7 +2337,7 @@ int ssh_pki_import_signature_blob(const ssh_string sig_blob, - enum ssh_keytypes_e type; - enum ssh_digest_e hash_type; - ssh_string algorithm = NULL, blob = NULL; -- ssh_buffer buf; -+ ssh_buffer buf = NULL; - const char *alg = NULL; - uint8_t flags = 0; - uint32_t counter = 0; -@@ -2697,9 +2697,9 @@ ssh_string ssh_pki_do_sign_agent(ssh_session session, - const ssh_key pubkey) - { - struct ssh_crypto_struct *crypto = NULL; -- ssh_string session_id; -- ssh_string sig_blob; -- ssh_buffer sig_buf; -+ ssh_string session_id = NULL; -+ ssh_string sig_blob = NULL; -+ ssh_buffer sig_buf = NULL; - int rc; - - crypto = ssh_packet_get_current_crypto(session, SSH_DIRECTION_BOTH); -diff --git a/src/pki_container_openssh.c b/src/pki_container_openssh.c -index 4314c5b..e32326b 100644 ---- a/src/pki_container_openssh.c -+++ b/src/pki_container_openssh.c -@@ -234,12 +234,12 @@ ssh_pki_openssh_import(const char *text_key, - bool private) - { - const char *ptr = text_key; -- const char *end; -- char *base64; -+ const char *end = NULL; -+ char *base64 = NULL; - int cmp; - int rc; - int i; -- ssh_buffer buffer = NULL, privkey_buffer=NULL; -+ ssh_buffer buffer = NULL, privkey_buffer = NULL; - char *magic = NULL, *ciphername = NULL, *kdfname = NULL; - uint32_t nkeys = 0, checkint1 = 0, checkint2 = 0xFFFF; - ssh_string kdfoptions = NULL; -@@ -536,16 +536,16 @@ ssh_string ssh_pki_openssh_privkey_export(const ssh_key privkey, - ssh_auth_callback auth_fn, - void *auth_data) - { -- ssh_buffer buffer; -+ ssh_buffer buffer= NULL; - ssh_string str = NULL; -- ssh_string pubkey_s=NULL; -+ ssh_string pubkey_s = NULL; - ssh_buffer privkey_buffer = NULL; - uint32_t rnd; - uint32_t rounds = 16; -- ssh_string salt=NULL; -- ssh_string kdf_options=NULL; -+ ssh_string salt = NULL; -+ ssh_string kdf_options = NULL; - int to_encrypt=0; -- unsigned char *b64; -+ unsigned char *b64 = NULL; - uint32_t str_len, len; - uint8_t padding = 1; - int ok; -diff --git a/src/pki_crypto.c b/src/pki_crypto.c -index 5b0d7de..6050993 100644 ---- a/src/pki_crypto.c -+++ b/src/pki_crypto.c -@@ -382,7 +382,7 @@ int pki_pubkey_build_ecdsa(ssh_key key, int nid, ssh_string e) - #else - int rc; - const char *group_name = OSSL_EC_curve_nid2name(nid); -- OSSL_PARAM_BLD *param_bld; -+ OSSL_PARAM_BLD *param_bld = NULL; - #endif /* OPENSSL_VERSION_NUMBER */ - - key->ecdsa_nid = nid; -@@ -2297,7 +2297,7 @@ static ssh_string pki_ecdsa_signature_to_blob(const ssh_signature sig) - const unsigned char *raw_sig_data = NULL; - size_t raw_sig_len; - -- ECDSA_SIG *ecdsa_sig; -+ ECDSA_SIG *ecdsa_sig = NULL; - - int rc; - -@@ -2614,8 +2614,8 @@ static int pki_signature_from_ecdsa_blob(UNUSED_PARAM(const ssh_key pubkey), - ECDSA_SIG *ecdsa_sig = NULL; - BIGNUM *pr = NULL, *ps = NULL; - -- ssh_string r; -- ssh_string s; -+ ssh_string r = NULL; -+ ssh_string s = NULL; - - ssh_buffer buf = NULL; - uint32_t rlen; -diff --git a/src/pki_ed25519.c b/src/pki_ed25519.c -index 6a5a4a8..0674fb6 100644 ---- a/src/pki_ed25519.c -+++ b/src/pki_ed25519.c -@@ -62,7 +62,7 @@ int pki_ed25519_sign(const ssh_key privkey, - size_t hlen) - { - int rc; -- uint8_t *buffer; -+ uint8_t *buffer = NULL; - uint64_t dlen = 0; - - buffer = malloc(hlen + ED25519_SIG_LEN); -@@ -104,8 +104,8 @@ int pki_ed25519_verify(const ssh_key pubkey, - size_t hlen) - { - uint64_t mlen = 0; -- uint8_t *buffer; -- uint8_t *buffer2; -+ uint8_t *buffer = NULL; -+ uint8_t *buffer2 = NULL; - int rc; - - if (pubkey == NULL || sig == NULL || -diff --git a/src/pki_ed25519_common.c b/src/pki_ed25519_common.c -index bdc6f6b..59a3b03 100644 ---- a/src/pki_ed25519_common.c -+++ b/src/pki_ed25519_common.c -@@ -213,7 +213,7 @@ int pki_ed25519_public_key_to_blob(ssh_buffer buffer, ssh_key key) - */ - ssh_string pki_ed25519_signature_to_blob(ssh_signature sig) - { -- ssh_string sig_blob; -+ ssh_string sig_blob = NULL; - int rc; - - #ifdef HAVE_OPENSSL_ED25519 -diff --git a/src/pki_gcrypt.c b/src/pki_gcrypt.c -index 418a46b..9fa3ab5 100644 ---- a/src/pki_gcrypt.c -+++ b/src/pki_gcrypt.c -@@ -121,7 +121,7 @@ static uint32_t asn1_get_len(ssh_buffer buffer) { - } - - static ssh_string asn1_get(ssh_buffer buffer, unsigned char want) { -- ssh_string str; -+ ssh_string str = NULLh; - unsigned char type; - uint32_t size; - -@@ -152,7 +152,7 @@ static ssh_string asn1_get_int(ssh_buffer buffer) { - - static ssh_string asn1_get_bit_string(ssh_buffer buffer) - { -- ssh_string str; -+ ssh_string str = NULL; - unsigned char type; - uint32_t size; - unsigned char unused, last, *p; -@@ -1882,9 +1882,9 @@ ssh_string pki_signature_to_blob(const ssh_signature sig) - case SSH_KEYTYPE_ECDSA_P521: - #ifdef HAVE_GCRYPT_ECC - { -- ssh_string R; -- ssh_string S; -- ssh_buffer b; -+ ssh_string R = NULL; -+ ssh_string S = NULL; -+ ssh_buffer b = NULL; - - b = ssh_buffer_new(); - if (b == NULL) { -@@ -2054,8 +2054,8 @@ ssh_signature pki_signature_from_blob(const ssh_key pubkey, - case SSH_KEYTYPE_SK_ECDSA: - #ifdef HAVE_GCRYPT_ECC - { /* build ecdsa siganature */ -- ssh_buffer b; -- ssh_string r, s; -+ ssh_buffer b = NULL; -+ ssh_string r = NULL, s = NULL; - uint32_t rlen; - - b = ssh_buffer_new(); -diff --git a/src/pki_mbedcrypto.c b/src/pki_mbedcrypto.c -index cb9d322..0181370 100644 ---- a/src/pki_mbedcrypto.c -+++ b/src/pki_mbedcrypto.c -@@ -1078,9 +1078,9 @@ ssh_string pki_signature_to_blob(const ssh_signature sig) - case SSH_KEYTYPE_ECDSA_P256: - case SSH_KEYTYPE_ECDSA_P384: - case SSH_KEYTYPE_ECDSA_P521: { -- ssh_string r; -- ssh_string s; -- ssh_buffer b; -+ ssh_string r = NULL; -+ ssh_string s = NULL; -+ ssh_buffer b = NULL; - int rc; - - b = ssh_buffer_new(); -@@ -1234,9 +1234,9 @@ ssh_signature pki_signature_from_blob(const ssh_key pubkey, - case SSH_KEYTYPE_ECDSA_P384: - case SSH_KEYTYPE_ECDSA_P521: - case SSH_KEYTYPE_SK_ECDSA: { -- ssh_buffer b; -- ssh_string r; -- ssh_string s; -+ ssh_buffer b = NULL; -+ ssh_string r = NULL; -+ ssh_string s = NULL; - size_t rlen; - - b = ssh_buffer_new(); -diff --git a/src/poll.c b/src/poll.c -index 828f5e0..a4a104c 100644 ---- a/src/poll.c -+++ b/src/poll.c -@@ -560,8 +560,8 @@ void ssh_poll_ctx_free(ssh_poll_ctx ctx) - - static int ssh_poll_ctx_resize(ssh_poll_ctx ctx, size_t new_size) - { -- ssh_poll_handle *pollptrs; -- ssh_pollfd_t *pollfds; -+ ssh_poll_handle *pollptrs = NULL; -+ ssh_pollfd_t *pollfds = NULL; - - pollptrs = realloc(ctx->pollptrs, sizeof(ssh_poll_handle) * new_size); - if (pollptrs == NULL) { -@@ -855,7 +855,7 @@ ssh_event_add_fd(ssh_event event, socket_t fd, short events, - ssh_event_callback cb, void *userdata) - { - ssh_poll_handle p; -- struct ssh_event_fd_wrapper *pw; -+ struct ssh_event_fd_wrapper *pw = NULL; - - if(event == NULL || event->ctx == NULL || cb == NULL - || fd == SSH_INVALID_SOCKET) { -@@ -925,7 +925,7 @@ int ssh_event_add_session(ssh_event event, ssh_session session) - { - ssh_poll_handle p; - #ifdef WITH_SERVER -- struct ssh_iterator *iterator; -+ struct ssh_iterator *iterator = NULL; - #endif - - if(event == NULL || event->ctx == NULL || session == NULL) { -@@ -1072,7 +1072,7 @@ int ssh_event_remove_session(ssh_event event, ssh_session session) - register size_t i, used; - int rc = SSH_ERROR; - #ifdef WITH_SERVER -- struct ssh_iterator *iterator; -+ struct ssh_iterator *iterator = NULL; - #endif - - if (event == NULL || event->ctx == NULL || session == NULL) { -diff --git a/src/server.c b/src/server.c -index cf54d0c..a8e3ac8 100644 ---- a/src/server.c -+++ b/src/server.c -@@ -85,8 +85,8 @@ int server_set_kex(ssh_session session) - { - struct ssh_kex_struct *server = &session->next_crypto->server_kex; - int i, j, rc; -- const char *wanted, *allowed; -- char *kept; -+ const char *wanted = NULL, *allowed = NULL; -+ char *kept = NULL; - char hostkeys[128] = {0}; - enum ssh_keytypes_e keytype; - size_t len; -@@ -219,9 +219,10 @@ int ssh_server_init_kex(ssh_session session) { - return server_set_kex(session); - } - --static int ssh_server_send_extensions(ssh_session session) { -+static int ssh_server_send_extensions(ssh_session session) -+{ - int rc; -- const char *hostkey_algorithms; -+ const char *hostkey_algorithms = NULL; - - SSH_LOG(SSH_LOG_PACKET, "Sending SSH_MSG_EXT_INFO"); - -@@ -286,8 +287,8 @@ ssh_get_key_params(ssh_session session, - ssh_key *privkey, - enum ssh_digest_e *digest) - { -- ssh_key pubkey; -- ssh_string pubkey_blob; -+ ssh_key pubkey = NULL; -+ ssh_string pubkey_blob = NULL; - int rc; - - switch(session->srv.hostkey) { -@@ -722,8 +723,9 @@ static int ssh_message_service_request_reply_default(ssh_message msg) { - * - * @returns SSH_OK when success otherwise SSH_ERROR - */ --int ssh_message_service_reply_success(ssh_message msg) { -- ssh_session session; -+int ssh_message_service_reply_success(ssh_message msg) -+{ -+ ssh_session session = NULL; - int rc; - - if (msg == NULL) { -@@ -1131,8 +1133,9 @@ int ssh_message_auth_reply_pk_ok(ssh_message msg, ssh_string algo, ssh_string pu - * - * @returns SSH_OK on success, otherwise SSH_ERROR - */ --int ssh_message_auth_reply_pk_ok_simple(ssh_message msg) { -- ssh_string algo; -+int ssh_message_auth_reply_pk_ok_simple(ssh_message msg) -+{ -+ ssh_string algo = NULL; - ssh_string pubkey_blob = NULL; - int ret; - -diff --git a/src/session.c b/src/session.c -index 6e1432a..cb45a2f 100644 ---- a/src/session.c -+++ b/src/session.c -@@ -58,7 +58,7 @@ - */ - ssh_session ssh_new(void) - { -- ssh_session session; -+ ssh_session session = NULL; - char *id = NULL; - int rc; - -@@ -280,7 +280,7 @@ void ssh_free(ssh_session session) - - /* options */ - if (session->opts.identity) { -- char *id; -+ char *id = NULL; - - for (id = ssh_list_pop_head(char *, session->opts.identity); - id != NULL; -@@ -291,7 +291,7 @@ void ssh_free(ssh_session session) - } - - if (session->opts.identity_non_exp) { -- char *id; -+ char *id = NULL; - - for (id = ssh_list_pop_head(char *, session->opts.identity_non_exp); - id != NULL; -@@ -1153,7 +1153,7 @@ int ssh_get_publickey_hash(const ssh_key key, - unsigned char **hash, - size_t *hlen) - { -- ssh_string blob; -+ ssh_string blob = NULL; - unsigned char *h = NULL; - int rc; - -@@ -1165,7 +1165,7 @@ int ssh_get_publickey_hash(const ssh_key key, - switch (type) { - case SSH_PUBLICKEY_HASH_SHA1: - { -- SHACTX ctx; -+ SHACTX ctx = NULL; - - h = calloc(1, SHA_DIGEST_LEN); - if (h == NULL) { -@@ -1197,7 +1197,7 @@ int ssh_get_publickey_hash(const ssh_key key, - break; - case SSH_PUBLICKEY_HASH_SHA256: - { -- SHA256CTX ctx; -+ SHA256CTX ctx = NULL; - - h = calloc(1, SHA256_DIGEST_LEN); - if (h == NULL) { -@@ -1229,7 +1229,7 @@ int ssh_get_publickey_hash(const ssh_key key, - break; - case SSH_PUBLICKEY_HASH_MD5: - { -- MD5CTX ctx; -+ MD5CTX ctx = NULL; - - /* In FIPS mode, we cannot use MD5 */ - if (ssh_fips_mode()) { -diff --git a/src/sftpserver.c b/src/sftpserver.c -index b3349e1..528ef6f 100644 ---- a/src/sftpserver.c -+++ b/src/sftpserver.c -@@ -299,8 +299,8 @@ void sftp_client_message_free(sftp_client_message msg) { - - int sftp_reply_name(sftp_client_message msg, const char *name, - sftp_attributes attr) { -- ssh_buffer out; -- ssh_string file; -+ ssh_buffer out = NULL; -+ ssh_string file = NULL; - - out = ssh_buffer_new(); - if (out == NULL) { -@@ -369,7 +369,7 @@ int sftp_reply_attr(sftp_client_message msg, sftp_attributes attr) { - - int sftp_reply_names_add(sftp_client_message msg, const char *file, - const char *longname, sftp_attributes attr) { -- ssh_string name; -+ ssh_string name = NULL; - - name = ssh_string_from_char(file); - if (name == NULL) { -@@ -435,8 +435,8 @@ int sftp_reply_names(sftp_client_message msg) { - - int sftp_reply_status(sftp_client_message msg, uint32_t status, - const char *message) { -- ssh_buffer out; -- ssh_string s; -+ ssh_buffer out = NULL; -+ ssh_string s = NULL; - - out = ssh_buffer_new(); - if (out == NULL) { -@@ -492,7 +492,7 @@ int sftp_reply_data(sftp_client_message msg, const void *data, int len) { - * valid info (or worse). - */ - ssh_string sftp_handle_alloc(sftp_session sftp, void *info) { -- ssh_string ret; -+ ssh_string ret = NULL; - uint32_t val; - uint32_t i; - -diff --git a/src/string.c b/src/string.c -index 4440348..670c2f3 100644 ---- a/src/string.c -+++ b/src/string.c -@@ -180,7 +180,7 @@ const char *ssh_string_get_char(struct ssh_string_struct *s) - */ - char *ssh_string_to_char(struct ssh_string_struct *s) { - size_t len; -- char *new; -+ char *new = NULL; - - if (s == NULL) { - return NULL; -@@ -219,7 +219,7 @@ void ssh_string_free_char(char *s) { - * @return Newly allocated copy of the string, NULL on error. - */ - struct ssh_string_struct *ssh_string_copy(struct ssh_string_struct *s) { -- struct ssh_string_struct *new; -+ struct ssh_string_struct *new = NULL; - size_t len; - - if (s == NULL) { -diff --git a/src/threads/winlocks.c b/src/threads/winlocks.c -index da60041..e63635e 100644 ---- a/src/threads/winlocks.c -+++ b/src/threads/winlocks.c -@@ -82,7 +82,7 @@ static struct ssh_threads_callbacks_struct ssh_threads_winlock = - - void ssh_mutex_lock(SSH_MUTEX *mutex) - { -- void *rc; -+ void *rc = NULL; - - CRITICAL_SECTION *mutex_tmp = NULL; - -diff --git a/src/wrapper.c b/src/wrapper.c -index d317dc4..43bf213 100644 ---- a/src/wrapper.c -+++ b/src/wrapper.c -@@ -152,7 +152,7 @@ static void cipher_free(struct ssh_cipher_struct *cipher) { - - struct ssh_crypto_struct *crypto_new(void) - { -- struct ssh_crypto_struct *crypto; -+ struct ssh_crypto_struct *crypto = NULL; - - crypto = malloc(sizeof(struct ssh_crypto_struct)); - if (crypto == NULL) { --- -2.33.0 - diff --git a/backport-0023-CVE-2025-4878-Properly-check-ret-to-avoid-NULL-dereference.patch b/backport-0023-CVE-2025-4878-Properly-check-ret-to-avoid-NULL-dereference.patch deleted file mode 100644 index 28128853553eae0cf2e5782e3322dce8a048aade..0000000000000000000000000000000000000000 --- a/backport-0023-CVE-2025-4878-Properly-check-ret-to-avoid-NULL-dereference.patch +++ /dev/null @@ -1,31 +0,0 @@ -From 8dc29f140be33b34e6e4a0c228bdce18eb610441 Mon Sep 17 00:00:00 2001 -From: Jakub Jelen -Date: Mon, 28 Apr 2025 11:04:55 +0200 -Subject: CVE-2025-4878 legacy: Properly check return value to avoid NULL - pointer dereference - -Signed-off-by: Jakub Jelen -Reviewed-by: Andreas Schneider - -Conflict:NA -Reference:https://git.libssh.org/projects/libssh.git/patch/?id=8dc29f140be33b34e6e4a0c228bdce18eb610441 ---- - src/legacy.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/src/legacy.c b/src/legacy.c -index 7b165db..c853cb3 100644 ---- a/src/legacy.c -+++ b/src/legacy.c -@@ -451,7 +451,7 @@ ssh_private_key privatekey_from_file(ssh_session session, - auth_fn, - auth_data, - &key); -- if (rc == SSH_ERROR) { -+ if (rc != SSH_OK) { - return NULL; - } - --- -2.33.0 - diff --git a/backport-0024-CVE-2025-5351-avoid-double-free-on-low-memory-conditions.patch b/backport-0024-CVE-2025-5351-avoid-double-free-on-low-memory-conditions.patch deleted file mode 100644 index e246076248b0c5ab6e9d11e56a713368ee2d2d98..0000000000000000000000000000000000000000 --- a/backport-0024-CVE-2025-5351-avoid-double-free-on-low-memory-conditions.patch +++ /dev/null @@ -1,46 +0,0 @@ -From acb158e8277adad473ed32ea1640a3d0b70d733b Mon Sep 17 00:00:00 2001 -From: Jakub Jelen -Date: Tue, 6 May 2025 22:43:31 +0200 -Subject: CVE-2025-5351 pki_crypto: Avoid double-free on low-memory -conditions - -Signed-off-by: Jakub Jelen -Reviewed-by: Andreas Schneider - -Conflict:set params to NULL after all OSSL_PARAM_free(params) -Reference:https://git.libssh.org/projects/libssh.git/patch/?id=acb158e8277adad473ed32ea1640a3d0b70d733b ---- - src/pki_crypto.c | 3 +++ - 1 file changed, 3 insertions(+) - -diff --git a/src/pki_crypto.c b/src/pki_crypto.c -index 5b0d7de..1c91d1e 100644 ---- a/src/pki_crypto.c -+++ b/src/pki_crypto.c -@@ -1962,6 +1962,7 @@ ssh_string pki_publickey_to_blob(const ssh_key key) - bignum_safe_free(bg); - bignum_safe_free(bpub_key); - OSSL_PARAM_free(params); -+ params = NULL; - #endif /* OPENSSL_VERSION_NUMBER */ - - break; -@@ -2023,6 +2024,7 @@ ssh_string pki_publickey_to_blob(const ssh_key key) - bignum_safe_free(bn); - bignum_safe_free(be); - OSSL_PARAM_free(params); -+ params = NULL; - #endif /* OPENSSL_VERSION_NUMBER */ - break; - } -@@ -2193,6 +2195,7 @@ fail: - bignum_safe_free(bn); - bignum_safe_free(be); - OSSL_PARAM_free(params); -+ params = NULL; - #endif /* OPENSSL_VERSION_NUMBER */ - - return NULL; --- -2.33.0 - diff --git a/backport-0025-CVE-2025-5987-correctly-detect-failures-of-chacha-init.patch b/backport-0025-CVE-2025-5987-correctly-detect-failures-of-chacha-init.patch deleted file mode 100644 index 0abb2a9f5e9661849743b4d375dc76cc7a240a75..0000000000000000000000000000000000000000 --- a/backport-0025-CVE-2025-5987-correctly-detect-failures-of-chacha-init.patch +++ /dev/null @@ -1,34 +0,0 @@ -From bc4804aa9bb1092a4ede288cb29cae4506c0e393 Mon Sep 17 00:00:00 2001 -From: Jakub Jelen -Date: Tue, 6 May 2025 22:51:41 +0200 -Subject: CVE-2025-5987 libcrypto: Correctly detect failures of chacha - initialization - -Signed-off-by: Jakub Jelen -Reviewed-by: Andreas Schneider - -Conflict:NA -Reference:https://git.libssh.org/projects/libssh.git/patch/?id=bc4804aa9bb1092a4ede288cb29cae4506c0e393 ---- - src/libcrypto.c | 4 ++-- - 1 file changed, 2 insertions(+), 2 deletions(-) - -diff --git a/src/libcrypto.c b/src/libcrypto.c -index 4f945d9..911b363 100644 ---- a/src/libcrypto.c -+++ b/src/libcrypto.c -@@ -777,9 +777,9 @@ chacha20_poly1305_set_key(struct ssh_cipher_struct *cipher, - SSH_LOG(SSH_LOG_WARNING, "EVP_CIPHER_CTX_new failed"); - goto out; - } -- ret = EVP_EncryptInit_ex(ctx->header_evp, EVP_chacha20(), NULL, -+ rv = EVP_EncryptInit_ex(ctx->header_evp, EVP_chacha20(), NULL, - u8key + CHACHA20_KEYLEN, NULL); -- if (ret != 1) { -+ if (rv != 1) { - SSH_LOG(SSH_LOG_WARNING, "EVP_CipherInit failed"); - goto out; - } --- -2.33.0 - diff --git a/backport-0026-CVE-2025-5372-Simplify-error-checking-in-ssh_kdf.patch b/backport-0026-CVE-2025-5372-Simplify-error-checking-in-ssh_kdf.patch deleted file mode 100644 index dbeb1ac60132a975deaa01a0b0001e97fc780bb2..0000000000000000000000000000000000000000 --- a/backport-0026-CVE-2025-5372-Simplify-error-checking-in-ssh_kdf.patch +++ /dev/null @@ -1,150 +0,0 @@ -From e2afe196d8d77c42b2a764ae86f92c2964221f69 Mon Sep 17 00:00:00 2001 -From: Jakub Jelen -Date: Wed, 14 May 2025 14:07:58 +0200 -Subject: CVE-2025-5372 libgcrypto: Simplify error checking and handling -of - return codes in ssh_kdf() - -Signed-off-by: Jakub Jelen -Reviewed-by: Andreas Schneider - -Conflict:NA -Reference:https://git.libssh.org/projects/libssh.git/patch/?id=e2afe196d8d77c42b2a764ae86f92c2964221f69 ---- - src/libcrypto.c | 63 ++++++++++++++++++++++--------------------------- - 1 file changed, 28 insertions(+), 35 deletions(-) - -diff --git a/src/libcrypto.c b/src/libcrypto.c -index 4f945d9..2815e2b 100644 ---- a/src/libcrypto.c -+++ b/src/libcrypto.c -@@ -163,7 +163,7 @@ int ssh_kdf(struct ssh_crypto_struct *crypto, - uint8_t key_type, unsigned char *output, - size_t requested_len) - { -- int rc = -1; -+ int ret = SSH_ERROR, rv; - #if OPENSSL_VERSION_NUMBER < 0x30000000L - EVP_KDF_CTX *ctx = EVP_KDF_CTX_new_id(EVP_KDF_SSHKDF); - #else -@@ -185,90 +185,83 @@ int ssh_kdf(struct ssh_crypto_struct *crypto, - } - - #if OPENSSL_VERSION_NUMBER < 0x30000000L -- rc = EVP_KDF_ctrl(ctx, EVP_KDF_CTRL_SET_MD, -+ rv = EVP_KDF_ctrl(ctx, EVP_KDF_CTRL_SET_MD, - sshkdf_digest_to_md(crypto->digest_type)); -- if (rc != 1) { -+ if (rv != 1) { - goto out; - } -- rc = EVP_KDF_ctrl(ctx, EVP_KDF_CTRL_SET_KEY, key, key_len); -- if (rc != 1) { -+ rv = EVP_KDF_ctrl(ctx, EVP_KDF_CTRL_SET_KEY, key, key_len); -+ if (rv != 1) { - goto out; - } -- rc = EVP_KDF_ctrl(ctx, EVP_KDF_CTRL_SET_SSHKDF_XCGHASH, -+ rv = EVP_KDF_ctrl(ctx, EVP_KDF_CTRL_SET_SSHKDF_XCGHASH, - crypto->secret_hash, crypto->digest_len); -- if (rc != 1) { -+ if (rv != 1) { - goto out; - } -- rc = EVP_KDF_ctrl(ctx, EVP_KDF_CTRL_SET_SSHKDF_TYPE, key_type); -- if (rc != 1) { -+ rv = EVP_KDF_ctrl(ctx, EVP_KDF_CTRL_SET_SSHKDF_TYPE, key_type); -+ if (rv != 1) { - goto out; - } -- rc = EVP_KDF_ctrl(ctx, EVP_KDF_CTRL_SET_SSHKDF_SESSION_ID, -+ rv = EVP_KDF_ctrl(ctx, EVP_KDF_CTRL_SET_SSHKDF_SESSION_ID, - crypto->session_id, crypto->session_id_len); -- if (rc != 1) { -+ if (rv != 1) { - goto out; - } -- rc = EVP_KDF_derive(ctx, output, requested_len); -- if (rc != 1) { -+ rv = EVP_KDF_derive(ctx, output, requested_len); -+ if (rv != 1) { - goto out; - } - #else -- rc = OSSL_PARAM_BLD_push_utf8_string(param_bld, OSSL_KDF_PARAM_DIGEST, -+ rv = OSSL_PARAM_BLD_push_utf8_string(param_bld, OSSL_KDF_PARAM_DIGEST, - md, strlen(md)); -- if (rc != 1) { -- rc = -1; -+ if (rv != 1) { - goto out; - } -- rc = OSSL_PARAM_BLD_push_octet_string(param_bld, OSSL_KDF_PARAM_KEY, -+ rv = OSSL_PARAM_BLD_push_octet_string(param_bld, OSSL_KDF_PARAM_KEY, - key, key_len); -- if (rc != 1) { -- rc = -1; -+ if (rv != 1) { - goto out; - } -- rc = OSSL_PARAM_BLD_push_octet_string(param_bld, -+ rv = OSSL_PARAM_BLD_push_octet_string(param_bld, - OSSL_KDF_PARAM_SSHKDF_XCGHASH, - crypto->secret_hash, - crypto->digest_len); -- if (rc != 1) { -- rc = -1; -+ if (rv != 1) { - goto out; - } -- rc = OSSL_PARAM_BLD_push_octet_string(param_bld, -+ rv = OSSL_PARAM_BLD_push_octet_string(param_bld, - OSSL_KDF_PARAM_SSHKDF_SESSION_ID, - crypto->session_id, - crypto->session_id_len); -- if (rc != 1) { -- rc = -1; -+ if (rv != 1) { - goto out; - } -- rc = OSSL_PARAM_BLD_push_utf8_string(param_bld, OSSL_KDF_PARAM_SSHKDF_TYPE, -+ rv = OSSL_PARAM_BLD_push_utf8_string(param_bld, OSSL_KDF_PARAM_SSHKDF_TYPE, - (const char*)&key_type, 1); -- if (rc != 1) { -- rc = -1; -+ if (rv != 1) { - goto out; - } - - params = OSSL_PARAM_BLD_to_param(param_bld); - if (params == NULL) { -- rc = -1; - goto out; - } - -- rc = EVP_KDF_derive(ctx, output, requested_len, params); -- if (rc != 1) { -- rc = -1; -+ rv = EVP_KDF_derive(ctx, output, requested_len, params); -+ if (rv != 1) { - goto out; - } - #endif /* OPENSSL_VERSION_NUMBER */ -- -+ ret = SSH_OK; - out: - #if OPENSSL_VERSION_NUMBER >= 0x30000000L - OSSL_PARAM_BLD_free(param_bld); - OSSL_PARAM_free(params); - #endif - EVP_KDF_CTX_free(ctx); -- if (rc < 0) { -- return rc; -+ if (ret < 0) { -+ return ret; - } - return 0; - } --- -2.33.0 - diff --git a/backport-0027-CVE-2025-8114-NULL-pointer-dereference-after-allocate-fail.patch b/backport-0027-CVE-2025-8114-NULL-pointer-dereference-after-allocate-fail.patch deleted file mode 100644 index 44025851d9f3300e7bf8214dd50d170eeeb70c4b..0000000000000000000000000000000000000000 --- a/backport-0027-CVE-2025-8114-NULL-pointer-dereference-after-allocate-fail.patch +++ /dev/null @@ -1,46 +0,0 @@ -From 53ac23ded4cb2c5463f6c4cd1525331bd578812d Mon Sep 17 00:00:00 2001 -From: Andreas Schneider -Date: Wed, 6 Aug 2025 15:17:59 +0200 -Subject: CVE-2025-8114: Fix NULL pointer dereference after allocation failure - -Signed-off-by: Andreas Schneider -Reviewed-by: Jakub Jelen - -Conflict: NA -Reference:https://git.libssh.org/projects/libssh.git/patch/?id=53ac23ded4cb2c5463f6c4cd1525331bd578812d ---- - src/kex.c | 4 ++++ - 1 file changed, 4 insertions(+) - -diff --git a/src/kex.c b/src/kex.c -index b8958b5..a834568 100644 ---- a/src/kex.c -+++ b/src/kex.c -@@ -1332,6 +1332,8 @@ int ssh_make_sessionid(ssh_session session) - ssh_log_hexdump("hash buffer", ssh_buffer_get(buf), ssh_buffer_get_len(buf)); - #endif - -+ /* Set rc for the following switch statement in case we goto error. */ -+ rc = SSH_ERROR; - switch (session->next_crypto->kex_type) { - case SSH_KEX_DH_GROUP1_SHA1: - case SSH_KEX_DH_GROUP14_SHA1: -@@ -1391,6 +1393,7 @@ int ssh_make_sessionid(ssh_session session) - session->next_crypto->secret_hash); - break; - } -+ - /* During the first kex, secret hash and session ID are equal. However, after - * a key re-exchange, a new secret hash is calculated. This hash will not replace - * but complement existing session id. -@@ -1399,6 +1402,7 @@ int ssh_make_sessionid(ssh_session session) - session->next_crypto->session_id = malloc(session->next_crypto->digest_len); - if (session->next_crypto->session_id == NULL) { - ssh_set_error_oom(session); -+ rc = SSH_ERROR; - goto error; - } - memcpy(session->next_crypto->session_id, session->next_crypto->secret_hash, --- -2.33.0 - diff --git a/backport-0028-CVE-2025-8277-adjust-packet-filter.patch b/backport-0028-CVE-2025-8277-adjust-packet-filter.patch deleted file mode 100644 index 780b22d3df54607a7023abd2a2cad242e78f1e37..0000000000000000000000000000000000000000 --- a/backport-0028-CVE-2025-8277-adjust-packet-filter.patch +++ /dev/null @@ -1,38 +0,0 @@ -From 4310a696f2d632c6742678077d703d9b9ff3bc0e Mon Sep 17 00:00:00 2001 -From: Jakub Jelen -Date: Tue, 5 Aug 2025 18:42:31 +0200 -Subject: CVE-2025-8277: packet: Adjust packet filter to work when DH-GEX is guessed wrongly - -Signed-off-by: Jakub Jelen -Reviewed-by: Andreas Schneider - -Conflict:NA -Reference:https://git.libssh.org/projects/libssh.git/patch/?id=4310a696f2d632c6742678077d703d9b9ff3bc0e - ---- - src/packet.c | 2 ++ - 1 file changed, 2 insertions(+) - -diff --git a/src/packet.c b/src/packet.c -index 36910499..5b32f46b 100644 ---- a/src/packet.c -+++ b/src/packet.c -@@ -294,6 +294,7 @@ static enum ssh_packet_filter_result_e ssh_packet_incoming_filter(ssh_session se - * or session_state == SSH_SESSION_STATE_INITIAL_KEX - * - dh_handshake_state == DH_STATE_INIT - * or dh_handshake_state == DH_STATE_INIT_SENT (re-exchange) -+ * or dh_handshake_state == DH_STATE_REQUEST_SENT (dh-gex) - * or dh_handshake_state == DH_STATE_FINISHED (re-exchange) - * - * Transitions: -@@ -313,6 +314,7 @@ static enum ssh_packet_filter_result_e ssh_packet_incoming_filter(ssh_session se - - if ((session->dh_handshake_state != DH_STATE_INIT) && - (session->dh_handshake_state != DH_STATE_INIT_SENT) && -+ (session->dh_handshake_state != DH_STATE_REQUEST_SENT) && - (session->dh_handshake_state != DH_STATE_FINISHED)) - { - rc = SSH_PACKET_DENIED; --- -cgit v1.2.3 - diff --git a/backport-0029-CVE-2025-8277-fix-memory-leak-and-free-allocated-pubkeys.patch b/backport-0029-CVE-2025-8277-fix-memory-leak-and-free-allocated-pubkeys.patch deleted file mode 100644 index d8013333a9db9dffcb9be06eab066b5c44ba6393..0000000000000000000000000000000000000000 --- a/backport-0029-CVE-2025-8277-fix-memory-leak-and-free-allocated-pubkeys.patch +++ /dev/null @@ -1,115 +0,0 @@ -From ccff22d3787c1355b3f0dcd09fe54d90acc55bf1 Mon Sep 17 00:00:00 2001 -From: Francesco Rollo ;Jakub Jelen -Date: Thu, 24 Jul 2025 16:30:07 +0300 -Subject: CVE-2025-8277: Fix memory leak of unused ephemeral key pair after client's wrong KEX guess -CVE-2025-8277: ecdh: Free previously allocated pubkeys - -Signed-off-by: Francesco Rollo ;Jakub Jelen -Reviewed-by: Andreas Schneider ;Andreas Schneider - -Conflict: adapt for src/ecdh_crypto.c, src/curve25519_crypto.c and src/curve25519_gcrypt.c don't exist -Reference:https://git.libssh.org/projects/libssh.git/patch/?id=ccff22d3787c1355b3f0dcd09fe54d90acc55bf1 -https://git.libssh.org/projects/libssh.git/patch/?id=c9d95ab0c7a52b231bcec09afbea71944ed0d852 ---- - src/dh_crypto.c | 5 +++++ - src/dh_key.c | 5 +++++ - src/ecdh_crypto.c | 10 ++++++++++ - src/ecdh_gcrypt.c | 7 +++++++ - src/ecdh_mbedcrypto.c | 6 ++++++ - 5 files changed, 33 insertions(+) - -diff --git a/src/dh_crypto.c b/src/dh_crypto.c -index 4dd9b50..cedfbc8 100644 ---- a/src/dh_crypto.c -+++ b/src/dh_crypto.c -@@ -407,6 +407,11 @@ int ssh_dh_init_common(struct ssh_crypto_struct *crypto) - struct dh_ctx *ctx = NULL; - int rc; - -+ /* Cleanup any previously allocated dh_ctx */ -+ if (crypto->dh_ctx != NULL) { -+ ssh_dh_cleanup(crypto); -+ } -+ - ctx = calloc(1, sizeof(*ctx)); - if (ctx == NULL) { - return SSH_ERROR; -diff --git a/src/dh_key.c b/src/dh_key.c -index 20d24a3..d9743ce 100644 ---- a/src/dh_key.c -+++ b/src/dh_key.c -@@ -237,6 +237,11 @@ int ssh_dh_init_common(struct ssh_crypto_struct *crypto) - struct dh_ctx *ctx = NULL; - int rc; - -+ /* Cleanup any previously allocated dh_ctx */ -+ if (crypto->dh_ctx != NULL) { -+ ssh_dh_cleanup(crypto); -+ } -+ - ctx = calloc(1, sizeof(*ctx)); - if (ctx == NULL) { - return SSH_ERROR; -diff --git a/src/ecdh_crypto.c b/src/ecdh_crypto.c -index b674b2e..2ce2ff2 100644 ---- a/src/ecdh_crypto.c -+++ b/src/ecdh_crypto.c -@@ -218,8 +218,18 @@ int ssh_client_ecdh_init(ssh_session session){ - SSH_STRING_FREE(client_pubkey); - return SSH_ERROR; - } -+/* Free any previously allocated privkey */ -+ if (session->next_crypto->ecdh_privkey != NULL) { -+#if OPENSSL_VERSION_NUMBER < 0x30000000L -+ EC_KEY_free(session->next_crypto->ecdh_privkey); -+#else -+ EVP_PKEY_free(session->next_crypto->ecdh_privkey); -+#endif -+ session->next_crypto->ecdh_privkey = NULL; -+ } - - session->next_crypto->ecdh_privkey = key; -+ ssh_string_free(session->next_crypto->ecdh_client_pubkey); - session->next_crypto->ecdh_client_pubkey = client_pubkey; - - /* register the packet callbacks */ -diff --git a/src/ecdh_gcrypt.c b/src/ecdh_gcrypt.c -index a8a8c37..5831a30 100644 ---- a/src/ecdh_gcrypt.c -+++ b/src/ecdh_gcrypt.c -@@ -101,8 +101,15 @@ int ssh_client_ecdh_init(ssh_session session) - goto out; - } - -+ /* Free any previously allocated privkey */ -+ if (session->next_crypto->ecdh_privkey != NULL) { -+ gcry_sexp_release(session->next_crypto->ecdh_privkey); -+ session->next_crypto->ecdh_privkey = NULL; -+ } - session->next_crypto->ecdh_privkey = key; - key = NULL; -+ -+ SSH_STRING_FREE(session->next_crypto->ecdh_client_pubkey); - session->next_crypto->ecdh_client_pubkey = client_pubkey; - client_pubkey = NULL; - -diff --git a/src/ecdh_mbedcrypto.c b/src/ecdh_mbedcrypto.c -index dda7392..6074b93 100644 ---- a/src/ecdh_mbedcrypto.c -+++ b/src/ecdh_mbedcrypto.c -@@ -70,6 +70,12 @@ int ssh_client_ecdh_init(ssh_session session) - return SSH_ERROR; - } - -+ /* Free any previously allocated privkey */ -+ if (session->next_crypto->ecdh_privkey != NULL) { -+ mbedtls_ecp_keypair_free(session->next_crypto->ecdh_privkey); -+ SAFE_FREE(session->next_crypto->ecdh_privkey); -+ } -+ - session->next_crypto->ecdh_privkey = malloc(sizeof(mbedtls_ecp_keypair)); - if (session->next_crypto->ecdh_privkey == NULL) { - return SSH_ERROR; --- -2.33.0 - diff --git a/backport-0030-CVE-2025-8277-mbedtls-avoid-leaking-ecdh-keys.patch b/backport-0030-CVE-2025-8277-mbedtls-avoid-leaking-ecdh-keys.patch deleted file mode 100644 index b080e0339eb8185e1c22028e071d2c20a3b92d2c..0000000000000000000000000000000000000000 --- a/backport-0030-CVE-2025-8277-mbedtls-avoid-leaking-ecdh-keys.patch +++ /dev/null @@ -1,46 +0,0 @@ -From ffed80f8c078122990a4eba2b275facd56dd43e0 Mon Sep 17 00:00:00 2001 -From: Jakub Jelen -Date: Wed, 6 Aug 2025 15:32:56 +0200 -Subject: CVE-2025-8277: mbedtls: Avoid leaking ecdh keys - -Signed-off-by: Jakub Jelen -Reviewed-by: Andreas Schneider - -Conflict:NA -Reference:https://git.libssh.org/projects/libssh.git/patch/?id=ffed80f8c078122990a4eba2b275facd56dd43e0 ---- - src/ecdh_mbedcrypto.c | 1 + - src/wrapper.c | 5 ++++- - 2 files changed, 5 insertions(+), 1 deletion(-) - -diff --git a/src/ecdh_mbedcrypto.c b/src/ecdh_mbedcrypto.c -index dda7392..bd054d6 100644 ---- a/src/ecdh_mbedcrypto.c -+++ b/src/ecdh_mbedcrypto.c -@@ -110,6 +110,7 @@ int ssh_client_ecdh_init(ssh_session session) - goto out; - } - -+ SSH_STRING_FREE(session->next_crypto->ecdh_client_pubkey); - session->next_crypto->ecdh_client_pubkey = client_pubkey; - client_pubkey = NULL; - -diff --git a/src/wrapper.c b/src/wrapper.c -index 43bf213..5f1c0e2 100644 ---- a/src/wrapper.c -+++ b/src/wrapper.c -@@ -190,7 +190,10 @@ void crypto_free(struct ssh_crypto_struct *crypto) - #endif /* OPENSSL_VERSION_NUMBER */ - #elif defined HAVE_GCRYPT_ECC - gcry_sexp_release(crypto->ecdh_privkey); --#endif -+#elif defined HAVE_LIBMBEDCRYPTO -+ mbedtls_ecp_keypair_free(crypto->ecdh_privkey); -+ SAFE_FREE(crypto->ecdh_privkey); -+#endif /* HAVE_LIBGCRYPT */ - crypto->ecdh_privkey = NULL; - } - #endif --- -2.33.0 - diff --git a/backport-Fix-regression-in-IPv6-addresses-in-hostname-parsing.patch b/backport-Fix-regression-in-IPv6-addresses-in-hostname-parsing.patch deleted file mode 100644 index 3a8b62a226baf51fdbaa19cc7d3128dd3095d589..0000000000000000000000000000000000000000 --- a/backport-Fix-regression-in-IPv6-addresses-in-hostname-parsing.patch +++ /dev/null @@ -1,138 +0,0 @@ -From 4f997aee7c7d7ea346b3e8ba505da0b7601ff318 Mon Sep 17 00:00:00 2001 -From: Jakub Jelen -Date: Fri, 22 Dec 2023 10:32:40 +0100 -Subject: Fix regression in IPv6 addresses in hostname parsing - -Signed-off-by: Jakub Jelen -Reviewed-by: Andreas Schneider - -Reference:https://git.libssh.org/projects/libssh.git/patch/?id=4f997aee7c7d7ea346b3e8ba505da0b7601ff318 -Conflict:NA - ---- - include/libssh/config_parser.h | 10 +++++++--- - src/config.c | 4 ++-- - src/config_parser.c | 16 +++++++++++----- - src/options.c | 10 ++-------- - 4 files changed, 22 insertions(+), 18 deletions(-) - -diff --git a/include/libssh/config_parser.h b/include/libssh/config_parser.h -index a7dd42a..256c63f 100644 ---- a/include/libssh/config_parser.h -+++ b/include/libssh/config_parser.h -@@ -30,6 +30,7 @@ - extern "C" { - #endif - -+#include - char *ssh_config_get_cmd(char **str); - - char *ssh_config_get_token(char **str); -@@ -49,14 +50,17 @@ int ssh_config_get_yesno(char **str, int notfound); - * be stored or NULL if we do not care about the result. - * @param[out] port Pointer to the location, where the new port will - * be stored or NULL if we do not care about the result. -+ * @param[in] ignore_port Set to true if the we should not attempt to parse -+ * port number. - * - * @returns SSH_OK if the provided string is in format of SSH URI, - * SSH_ERROR on failure - */ - int ssh_config_parse_uri(const char *tok, -- char **username, -- char **hostname, -- char **port); -+ char **username, -+ char **hostname, -+ char **port, -+ bool ignore_port); - - #ifdef __cplusplus - } -diff --git a/src/config.c b/src/config.c -index c5c4012..273db7c 100644 ---- a/src/config.c -+++ b/src/config.c -@@ -464,7 +464,7 @@ ssh_config_parse_proxy_jump(ssh_session session, const char *s, bool do_parsing) - } - if (parse_entry) { - /* We actually care only about the first item */ -- rv = ssh_config_parse_uri(cp, &username, &hostname, &port); -+ rv = ssh_config_parse_uri(cp, &username, &hostname, &port, false); - /* The rest of the list needs to be passed on */ - if (endp != NULL) { - next = strdup(endp + 1); -@@ -475,7 +475,7 @@ ssh_config_parse_proxy_jump(ssh_session session, const char *s, bool do_parsing) - } - } else { - /* The rest is just sanity-checked to avoid failures later */ -- rv = ssh_config_parse_uri(cp, NULL, NULL, NULL); -+ rv = ssh_config_parse_uri(cp, NULL, NULL, NULL, false); - } - if (rv != SSH_OK) { - goto out; -diff --git a/src/config_parser.c b/src/config_parser.c -index b8b9461..d4b2d2c 100644 ---- a/src/config_parser.c -+++ b/src/config_parser.c -@@ -162,9 +162,10 @@ int ssh_config_get_yesno(char **str, int notfound) - } - - int ssh_config_parse_uri(const char *tok, -- char **username, -- char **hostname, -- char **port) -+ char **username, -+ char **hostname, -+ char **port, -+ bool ignore_port) - { - char *endp = NULL; - long port_n; -@@ -210,12 +211,17 @@ int ssh_config_parse_uri(const char *tok, - if (endp == NULL) { - goto error; - } -- } else { -- /* Hostnames or aliases expand to the last colon or to the end */ -+ } else if (!ignore_port) { -+ /* Hostnames or aliases expand to the last colon (if port is requested) -+ * or to the end */ - endp = strrchr(tok, ':'); - if (endp == NULL) { - endp = strchr(tok, '\0'); - } -+ } else { -+ /* If no port is requested, expand to the end of line -+ * (to accommodate the IPv6 addresses) */ -+ endp = strchr(tok, '\0'); - } - if (tok == endp) { - /* Zero-length hostnames are not valid */ -diff --git a/src/options.c b/src/options.c -index 3851145..b3ecffe 100644 ---- a/src/options.c -+++ b/src/options.c -@@ -516,17 +516,11 @@ int ssh_options_set(ssh_session session, enum ssh_options_e type, - ssh_set_error_invalid(session); - return -1; - } else { -- char *username = NULL, *hostname = NULL, *port = NULL; -- rc = ssh_config_parse_uri(value, &username, &hostname, &port); -+ char *username = NULL, *hostname = NULL; -+ rc = ssh_config_parse_uri(value, &username, &hostname, NULL, true); - if (rc != SSH_OK) { - return -1; - } -- if (port != NULL) { -- SAFE_FREE(username); -- SAFE_FREE(hostname); -- SAFE_FREE(port); -- return -1; -- } - if (username != NULL) { - SAFE_FREE(session->opts.username); - session->opts.username = username; --- -2.43.0 - diff --git a/libssh-0.10.5.tar.xz b/libssh-0.10.5.tar.xz deleted file mode 100644 index 2a2603fce87e03459cfd117cd0fb7c6ab2f1b80c..0000000000000000000000000000000000000000 Binary files a/libssh-0.10.5.tar.xz and /dev/null differ diff --git a/libssh-0.10.5.tar.xz.asc b/libssh-0.10.5.tar.xz.asc deleted file mode 100644 index 01c568576e041899e9643d765070c88306fb4e28..0000000000000000000000000000000000000000 --- a/libssh-0.10.5.tar.xz.asc +++ /dev/null @@ -1,16 +0,0 @@ ------BEGIN PGP SIGNATURE----- - -iQIzBAABCgAdFiEEjf9T4Y8qvI2PPJIjfuD8TcwBTj0FAmRTm30ACgkQfuD8TcwB -Tj0TBQ/+MS5qNXgV8I/3s0k6jpzTsEMdozOZ7RYiJg9i9UzCGsIuJ0aiMl+G1aFH -UJOkLlHgGXTSCeZk4aoSTky2jEOezcFgsi0v9j8nmxRTjlDDAY0KxOoA//wc5nQ0 -fgQKUbX0SrtIbe9qpffoGBjaEap2ICAiM7a5PJ+Js0RQ944TqmkWmhGP/2XhxsF9 -0TJ6e4ilSg/mTBV5GemLTRSc+MgFoh5jJiV1+zmkOw5bBvPx7/KgsdmhoZ63prFI -8LvfChEEx50lyTXC8eLW4uSvO5tMHyAwDNBJcKOccp5yqEr147S1pZL8iNS0C2EF -/vG7zRDa3dv81xJjuPVdO40/GE77omp1IWC3i4ZskaAocGOmHo7KSwJ/7MjtAuJT -QgqeTPHjENRYbB6FvyesHpWzesORFIxQtCMxugVpEPcc3WLIRNLvJGa7rofAGJJf -u5uLyzmBuyAWm5gpPMyLRy2ysAgBi7NVusnAuR4v28r8YYpGrwTG+epJ1fV6MKWV -tlV8aCY51H7WVmDNJlwyJOwEZWzRdi9n3e22hEm79+cj3WKY3uwYwJI4s0CgcsUw -OzEZt97Yy+pSvdOokgNHRz0tGoDXZw55PF4+mcyvXSQfZJ2QCL7q7dJ/7DmibGgY -LtsN5bSfzXgEBqpty/sD5HSSt1/fNICJjfuiTKtjKXMD45wBUkE= -=IAN/ ------END PGP SIGNATURE----- diff --git a/libssh-0.11.3.tar.xz b/libssh-0.11.3.tar.xz new file mode 100644 index 0000000000000000000000000000000000000000..e99ea82abaf217db444f04cebd0976a525af4817 Binary files /dev/null and b/libssh-0.11.3.tar.xz differ diff --git a/libssh.keyring b/libssh.keyring deleted file mode 100644 index 411bf36750f0fc4a8856034415e39c7116559ee4..0000000000000000000000000000000000000000 Binary files a/libssh.keyring and /dev/null differ diff --git a/libssh.spec b/libssh.spec index 059647e925ecd54902cd8772cf77f6641dd252fa..bd4ec68e0f91078002b62bd39594a761fb0c0131 100644 --- a/libssh.spec +++ b/libssh.spec @@ -1,47 +1,11 @@ -%undefine __cmake_in_source_build - Name: libssh -Version: 0.10.5 -Release: 9 +Version: 0.11.3 +Release: 1 Summary: A library implementing the SSH protocol License: LGPL-2.1-or-later URL: https://www.libssh.org -Source0: https://www.libssh.org/files/0.10/%{name}-%{version}.tar.xz -Source1: https://www.libssh.org/files/0.10/%{name}-%{version}.tar.xz.asc -Source2: https://cryptomilk.org/gpgkey-8DFF53E18F2ABC8D8F3C92237EE0FC4DCC014E3D.gpg#/%{name}.keyring - -Patch1: backport-0001-CVE-2023-6004-torture_config-Allow-multiple-in-usern.patch -Patch2: backport-0002-CVE-2023-6004-config_parser-Allow-multiple-in-userna.patch -Patch3: backport-0003-CVE-2023-6004-options-Simplify-the-hostname-parsing-.patch -Patch4: backport-0004-CVE-2023-6004-misc-Add-function-to-check-allowed-cha.patch -Patch5: backport-0005-CVE-2023-6004-torture_misc-Add-test-for-ssh_check_ho.patch -Patch6: backport-0006-CVE-2023-6004-config_parser-Check-for-valid-syntax-o.patch -Patch7: backport-0007-CVE-2023-6004-torture_proxycommand-Add-test-for-prox.patch -Patch8: backport-0008-CVE-2023-6004-torture_misc-Add-test-for-ssh_is_ipadd.patch -Patch9: backport-0009-CVE-2023-6004-misc-Add-ipv6-link-local-check-for-an-.patch -Patch10: backport-0010-CVE-2023-6004-torture_misc-Add-tests-for-ipv6-link-l.patch -Patch11: backport-0011-CVE-2023-48795-client-side-mitigation.patch -Patch12: backport-0012-CVE-2023-48795-Server-side-mitigations.patch -Patch13: backport-0013-CVE-2023-48795-Strip-extensions-from-both-kex-lists-.patch -Patch14: backport-0014-CVE-2023-48795-tests-Adjust-calculation-to-strict-ke.patch -Patch15: backport-0015-CVE-2023-6918-kdf-Reformat.patch -Patch16: backport-0016-CVE-2023-6918-Remove-unused-evp-functions-and-types.patch -Patch17: backport-0017-CVE-2023-6918-Systematically-check-return-values-whe.patch -Patch18: backport-0018-CVE-2023-6918-kdf-Detect-context-init-failures.patch -Patch19: backport-0019-CVE-2023-6918-tests-Code-coverage-for-ssh_get_pubkey.patch -Patch20: backport-Fix-regression-in-IPv6-addresses-in-hostname-parsing.patch -Patch21: backport-0020-CVE-2025-5318-fix-possible-buffer-overrun.patch -Patch22: backport-0021-CVE-2025-4877-prevent-integer-overflow-and-potential-OOB.patch -Patch23: backport-0022-CVE-2025-4878-Initialize-pointers-where-posibble.patch -Patch24: backport-0023-CVE-2025-4878-Properly-check-ret-to-avoid-NULL-dereference.patch -Patch25: backport-0024-CVE-2025-5351-avoid-double-free-on-low-memory-conditions.patch -Patch26: backport-0025-CVE-2025-5987-correctly-detect-failures-of-chacha-init.patch -Patch27: backport-0026-CVE-2025-5372-Simplify-error-checking-in-ssh_kdf.patch -Patch28: backport-0027-CVE-2025-8114-NULL-pointer-dereference-after-allocate-fail.patch -Patch29: backport-0028-CVE-2025-8277-adjust-packet-filter.patch -Patch30: backport-0029-CVE-2025-8277-fix-memory-leak-and-free-allocated-pubkeys.patch -Patch31: backport-0030-CVE-2025-8277-mbedtls-avoid-leaking-ecdh-keys.patch +Source0: https://www.libssh.org/files/0.11/%{name}-%{version}.tar.xz BuildRequires: cmake gcc-c++ gnupg2 openssl-devel pkgconfig zlib-devel BuildRequires: krb5-devel libcmocka-devel openssh-clients openssh-server @@ -70,7 +34,6 @@ applications that use %{name}. %package_help %prep -gpgv2 --quiet --keyring %{SOURCE2} %{SOURCE1} %{SOURCE0} %autosetup -p1 %build @@ -113,6 +76,9 @@ popd %doc CHANGELOG README %changelog +* Fri Oct 03 2025 Funda Wang - 0.11.3-1 +- update to 0.11.3 + * Wed Sep 24 2025 zhangbinqin - 0.10.5-9 - Type:bugfix - Id:NA