File libssh-CVE-2026-0966-tests-Test-coverage-for-ssh_get_hexa.patch of Package libssh.42763
From b156391833c66322436cf177d57e10b0325fbcc8 Mon Sep 17 00:00:00 2001
From: Jakub Jelen <jjelen@redhat.com>
Date: Thu, 8 Jan 2026 12:10:16 +0100
Subject: [PATCH 06/12] CVE-2026-0966 tests: Test coverage for ssh_get_hexa
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Pavol Žáčik <pzacik@redhat.com>
(cherry picked from commit 9be83584a56580da5a2f41e47137056dc0249b52)
Index: libssh-0.9.8/tests/unittests/torture_misc.c
===================================================================
--- libssh-0.9.8.orig/tests/unittests/torture_misc.c
+++ libssh-0.9.8/tests/unittests/torture_misc.c
@@ -777,6 +777,36 @@ static void torture_ssh_is_ipaddr(void *
assert_int_equal(rc, 0);
}
+static void torture_ssh_get_hexa(void **state)
+{
+ const unsigned char *bin = NULL;
+ char *hex = NULL;
+
+ (void)state;
+
+ /* Null pointer should not crash */
+ bin = NULL;
+ hex = ssh_get_hexa(bin, 0);
+ assert_null(hex);
+
+ /* Null pointer should not crash regardless the length */
+ bin = NULL;
+ hex = ssh_get_hexa(bin, 99);
+ assert_null(hex);
+
+ /* Zero length input is not much useful. Just expect NULL too */
+ bin = (const unsigned char *)"";
+ hex = ssh_get_hexa(bin, 0);
+ assert_null(hex);
+
+ /* Valid inputs */
+ bin = (const unsigned char *)"\x00\xFF";
+ hex = ssh_get_hexa(bin, 2);
+ assert_non_null(hex);
+ assert_string_equal(hex, "00:ff");
+ ssh_string_free_char(hex);
+}
+
int torture_run_tests(void) {
int rc;
struct CMUnitTest tests[] = {
@@ -801,6 +831,7 @@ int torture_run_tests(void) {
cmocka_unit_test(torture_ssh_quote_file_name),
cmocka_unit_test(torture_ssh_check_hostname_syntax),
cmocka_unit_test(torture_ssh_is_ipaddr),
+ cmocka_unit_test(torture_ssh_get_hexa),
};
ssh_init();