From cce0f0919194e77b9e169aa817b346218303106e Mon Sep 17 00:00:00 2001 From: Chenxi Mao Date: Mon, 1 Nov 2021 16:22:41 +0800 Subject: [PATCH] libkae: fix build warnings on aarch64 from source There are several build warnings on aarch64 [ 34s] ./utils/engine_log.h:73:13: error: ignoring return value of 'ftruncate' declared with attribute 'warn_unused_result' [-Werror=unused-result] [ 34s] 73 | ftruncate(g_kae_debug_log_file->_fileno, 0); \ [ 34s] | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [ 84s] alg/pkey/hpre_rsa.c: In function 'hpre_rsa_private_encrypt': [ 84s] alg/pkey/hpre_rsa.c:546:5: error: 'num_bytes' may be used uninitialized in this function [-Werror=maybe-uninitialized] [ 84s] 546 | hpre_free_bn_ctx_buf(bn_ctx, in_buf, num_bytes); [ 84s] | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [ 84s] alg/pkey/hpre_rsa.c: In function 'hpre_rsa_public_encrypt': [ 84s] alg/pkey/hpre_rsa.c:440:5: error: 'num_bytes' may be used uninitialized in this function [-Werror=maybe-uninitialized] [ 84s] 440 | hpre_free_bn_ctx_buf(bn_ctx, in_buf, num_bytes); [ 84s] | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [ 84s] alg/pkey/hpre_rsa.c:440:5: error: 'bn_ctx' may be used uninitialized in this function [-Werror=maybe-uninitialized] Add a patch to fix build warning from source code level. This patch is fix build warning and no functional change. Signed-off-by: Chenxi Mao --- ...-libkae-fix-build-warning-on-aarch64.patch | 120 ++++++++++++++++++ kae.spec | 6 +- 2 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 0003-libkae-fix-build-warning-on-aarch64.patch diff --git a/0003-libkae-fix-build-warning-on-aarch64.patch b/0003-libkae-fix-build-warning-on-aarch64.patch new file mode 100644 index 0000000..a0a92d6 --- /dev/null +++ b/0003-libkae-fix-build-warning-on-aarch64.patch @@ -0,0 +1,120 @@ +From 6c932f2e8e9294f9415bb4a62c6da75125eeac60 Mon Sep 17 00:00:00 2001 +From: Chenxi Mao +Date: Fri, 29 Oct 2021 12:24:00 +0800 +Subject: [PATCH 1/1] libkae: fix build warning on aarch64 + +This patch to fix below error on aarch64 +[ 34s] ./utils/engine_log.h:73:13: error: ignoring return value of 'ftruncate' declared with attribute 'warn_unused_result' [-Werror=unused-result] +[ 34s] 73 | ftruncate(g_kae_debug_log_file->_fileno, 0); \ +[ 34s] | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +[ 84s] alg/pkey/hpre_rsa.c: In function 'hpre_rsa_private_encrypt': +[ 84s] alg/pkey/hpre_rsa.c:546:5: error: 'num_bytes' may be used uninitialized in this function [-Werror=maybe-uninitialized] +[ 84s] 546 | hpre_free_bn_ctx_buf(bn_ctx, in_buf, num_bytes); +[ 84s] | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +[ 84s] alg/pkey/hpre_rsa.c: In function 'hpre_rsa_public_encrypt': +[ 84s] alg/pkey/hpre_rsa.c:440:5: error: 'num_bytes' may be used uninitialized in this function [-Werror=maybe-uninitialized] +[ 84s] 440 | hpre_free_bn_ctx_buf(bn_ctx, in_buf, num_bytes); +[ 84s] | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +[ 84s] alg/pkey/hpre_rsa.c:440:5: error: 'bn_ctx' may be used uninitialized in this function [-Werror=maybe-uninitialized] + +There is no functional change. + +Signed-off-by: Chenxi Mao +--- + KAE/alg/pkey/hpre_rsa.c | 12 ++++++++---- + KAE/utils/engine_log.c | 5 +++-- + KAE/utils/engine_log.h | 5 +++-- + 3 files changed, 14 insertions(+), 8 deletions(-) + +diff --git a/KAE/alg/pkey/hpre_rsa.c b/KAE/alg/pkey/hpre_rsa.c +index f7cc8bd..e7e28a4 100644 +--- a/KAE/alg/pkey/hpre_rsa.c ++++ b/KAE/alg/pkey/hpre_rsa.c +@@ -381,6 +381,8 @@ static int hpre_rsa_public_encrypt(int flen, const unsigned char *from, + BIGNUM *ret_bn = NULL; + hpre_engine_ctx_t *eng_ctx = NULL; + unsigned char *in_buf = NULL; ++ BN_CTX *bn_ctx = NULL; ++ int num_bytes = 0; + + if (hpre_rsa_check_para(flen, from, to, rsa) != HPRE_CRYPTO_SUCC) { + return HPRE_CRYPTO_FAIL; +@@ -403,13 +405,13 @@ static int hpre_rsa_public_encrypt(int flen, const unsigned char *from, + GOTOEND_IF(ret != HPRE_CRYPTO_SUCC, "check public key fail", + KAE_F_HPRE_RSA_PUBENC, KAE_R_PUBLIC_KEY_INVALID); + +- BN_CTX *bn_ctx = BN_CTX_new(); ++ bn_ctx = BN_CTX_new(); + GOTOEND_IF(bn_ctx == NULL, "bn_ctx MALLOC FAILED!", + KAE_F_HPRE_RSA_PUBENC, KAE_R_MALLOC_FAILURE); + + BN_CTX_start(bn_ctx); + ret_bn = BN_CTX_get(bn_ctx); +- int num_bytes = BN_num_bytes(n); ++ num_bytes = BN_num_bytes(n); + in_buf = (unsigned char *)OPENSSL_malloc(num_bytes); + GOTOEND_IF(ret_bn == NULL || in_buf == NULL, "PUBLIC_ENCRYPT RSA MALLOC FAILED!", + KAE_F_HPRE_RSA_PUBENC, KAE_R_MALLOC_FAILURE); +@@ -467,6 +469,8 @@ static int hpre_rsa_private_encrypt(int flen, const unsigned char *from, + const BIGNUM *dmq1 = (const BIGNUM *)NULL; + const BIGNUM *iqmp = (const BIGNUM *)NULL; + unsigned char *in_buf = (unsigned char *)NULL; ++ BN_CTX *bn_ctx = NULL; ++ int num_bytes = 0; + + if (hpre_rsa_check_para(flen, from, to, rsa) != HPRE_CRYPTO_SUCC) { + return HPRE_CRYPTO_FAIL; +@@ -485,7 +489,7 @@ static int hpre_rsa_private_encrypt(int flen, const unsigned char *from, + goto end_soft; + } + +- BN_CTX *bn_ctx = BN_CTX_new(); ++ bn_ctx = BN_CTX_new(); + GOTOEND_IF(bn_ctx == NULL, "PRI_ENC MALLOC_FAILURE ", + KAE_F_HPRE_RSA_PRIENC, KAE_R_MALLOC_FAILURE); + +@@ -496,7 +500,7 @@ static int hpre_rsa_private_encrypt(int flen, const unsigned char *from, + RSA_get0_crt_params(rsa, &dmp1, &dmq1, &iqmp); + int version = RSA_get_version(rsa); + RSA_get0_key(rsa, &n, &e, &d); +- int num_bytes = BN_num_bytes(n); ++ num_bytes = BN_num_bytes(n); + in_buf = (unsigned char *)OPENSSL_malloc(num_bytes); + GOTOEND_IF(bn_ret == NULL || in_buf == NULL, "OpenSSL malloc failure", + KAE_F_HPRE_RSA_PRIENC, KAE_R_MALLOC_FAILURE); +diff --git a/KAE/utils/engine_log.c b/KAE/utils/engine_log.c +index 00e9c96..e068ec9 100644 +--- a/KAE/utils/engine_log.c ++++ b/KAE/utils/engine_log.c +@@ -164,8 +164,9 @@ void ENGINE_LOG_LIMIT(int level, int times, int limit, const char *fmt, ...) + fprintf(g_kae_debug_log_file, "\n"); + if (ftell(g_kae_debug_log_file) > KAE_LOG_MAX_SIZE) { + kae_save_log(g_kae_debug_log_file); +- ftruncate(g_kae_debug_log_file->_fileno, 0); +- fseek(g_kae_debug_log_file, 0, SEEK_SET); ++ if (ftruncate(g_kae_debug_log_file->_fileno, 0) == 0) { ++ fseek(g_kae_debug_log_file, 0, SEEK_SET); ++ } + } + pthread_mutex_unlock(&g_debug_file_mutex); + flock(g_kae_debug_log_file->_fileno, LOCK_UN); +diff --git a/KAE/utils/engine_log.h b/KAE/utils/engine_log.h +index 51cfb7b..08d7c6d 100644 +--- a/KAE/utils/engine_log.h ++++ b/KAE/utils/engine_log.h +@@ -70,8 +70,9 @@ void ENGINE_LOG_LIMIT(int level, int times, int limit, const char *fmt, ...); + } \ + if (ftell(g_kae_debug_log_file) > KAE_LOG_MAX_SIZE) { \ + kae_save_log(g_kae_debug_log_file); \ +- ftruncate(g_kae_debug_log_file->_fileno, 0); \ +- fseek(g_kae_debug_log_file, 0, SEEK_SET); \ ++ if (ftruncate(g_kae_debug_log_file->_fileno, 0) == 0) { \ ++ fseek(g_kae_debug_log_file, 0, SEEK_SET); \ ++ } \ + } \ + pthread_mutex_unlock(&g_debug_file_mutex); \ + flock(g_kae_debug_log_file->_fileno, LOCK_UN); \ +-- +2.32.0 + diff --git a/kae.spec b/kae.spec index a14de2c..a9da521 100644 --- a/kae.spec +++ b/kae.spec @@ -3,7 +3,7 @@ Name: libkae Summary: Huawei Kunpeng Accelerator Engine Version: 1.2.10 -Release: 5 +Release: 6 License: Apache-2.0 Source: %{name}-%{version}.tar.gz Vendor: Huawei Corporation @@ -19,6 +19,7 @@ ExclusiveArch: aarch64 Patch0001: 0001-Don-t-redefine-gettid-if-glibc-provides-it.patch Patch0002: 0002-fix-pthread_yield.patch +Patch0003: 0003-libkae-fix-build-warning-on-aarch64.patch %description This package contains the Huawei Kunpeng Accelerator Engine @@ -68,6 +69,9 @@ fi /sbin/ldconfig %changelog +* Mon Nov 1 2021 Chenxi Mao 1.2.10-6 +- Fix KAE build warning from source on aarch64 + * Thu Aug 12 2021 caodongxia 1.2.10-5 - Fix pthread_yield is deprecated -- Gitee