From 7c1cd5ae1c17931f45baf3e39fd2696c16704c2c Mon Sep 17 00:00:00 2001 From: PiotrBzdrega Date: Tue, 13 Feb 2024 16:59:05 +0100 Subject: [PATCH 1/3] move entropy init prior arguments number recognition Signed-off-by: PiotrBzdrega --- ChangeLog.d/gen-key-segfault.txt | 3 +++ programs/pkey/gen_key.c | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 ChangeLog.d/gen-key-segfault.txt diff --git a/ChangeLog.d/gen-key-segfault.txt b/ChangeLog.d/gen-key-segfault.txt new file mode 100644 index 000000000000..7f8c39b09850 --- /dev/null +++ b/ChangeLog.d/gen-key-segfault.txt @@ -0,0 +1,3 @@ +Bugfix + * Avoid segmentation fault caused by releasing not initialized + entropy resource in gen_key example. Fixes #8809 \ No newline at end of file diff --git a/programs/pkey/gen_key.c b/programs/pkey/gen_key.c index 8ad26276673f..eab5c30ac34e 100644 --- a/programs/pkey/gen_key.c +++ b/programs/pkey/gen_key.c @@ -188,6 +188,7 @@ int main(int argc, char *argv[]) mbedtls_mpi_init(&D); mbedtls_mpi_init(&E); mbedtls_mpi_init(&DP); mbedtls_mpi_init(&DQ); mbedtls_mpi_init(&QP); + mbedtls_entropy_init(&entropy); mbedtls_pk_init(&key); mbedtls_ctr_drbg_init(&ctr_drbg); memset(buf, 0, sizeof(buf)); @@ -275,7 +276,6 @@ int main(int argc, char *argv[]) mbedtls_printf("\n . Seeding the random number generator..."); fflush(stdout); - mbedtls_entropy_init(&entropy); #if !defined(_WIN32) && defined(MBEDTLS_FS_IO) if (opt.use_dev_random) { if ((ret = mbedtls_entropy_add_source(&entropy, dev_random_entropy_poll, From 14e4727d0ededb1a0174f1d48ecc856d31a29063 Mon Sep 17 00:00:00 2001 From: PiotrBzdrega Date: Tue, 13 Feb 2024 17:09:40 +0100 Subject: [PATCH 2/3] fill out missing dot in changelog Signed-off-by: PiotrBzdrega --- ChangeLog.d/gen-key-segfault.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ChangeLog.d/gen-key-segfault.txt b/ChangeLog.d/gen-key-segfault.txt index 7f8c39b09850..4fb2d1f858e5 100644 --- a/ChangeLog.d/gen-key-segfault.txt +++ b/ChangeLog.d/gen-key-segfault.txt @@ -1,3 +1,3 @@ Bugfix * Avoid segmentation fault caused by releasing not initialized - entropy resource in gen_key example. Fixes #8809 \ No newline at end of file + entropy resource in gen_key example. Fixes #8809. \ No newline at end of file From c609654665b2a0c49ce1aca3748c0edb164729a2 Mon Sep 17 00:00:00 2001 From: PiotrBzdrega Date: Tue, 13 Feb 2024 22:12:23 +0100 Subject: [PATCH 3/3] newline at end of changelog file Signed-off-by: PiotrBzdrega --- ChangeLog.d/gen-key-segfault.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ChangeLog.d/gen-key-segfault.txt b/ChangeLog.d/gen-key-segfault.txt index 4fb2d1f858e5..fefc702726b9 100644 --- a/ChangeLog.d/gen-key-segfault.txt +++ b/ChangeLog.d/gen-key-segfault.txt @@ -1,3 +1,3 @@ Bugfix * Avoid segmentation fault caused by releasing not initialized - entropy resource in gen_key example. Fixes #8809. \ No newline at end of file + entropy resource in gen_key example. Fixes #8809.