Skip to contentSkip to conversation

optee-test: Suppress new gcc-15 -Wunterminated-string-initialization

PATCH In review Denys Dmytriyenko 2 participants 3 messages May 7, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 optee-test: Suppress new gcc-15 -Wunterminated-string-initialization

From: Denys Dmytriyenko <[email protected]>

Mark corresponding arrays with nonstring attribute to suppress the new gcc-15 warning -Wunterminated-string-initialization that becomes an error due to the global -Werror.

---
 ...-15-Wunterminated-string-initializat.patch | 69 +++++++++++++++++++
 .../optee/optee-test_4.4.0.bb                 |  1 +
 2 files changed, 70 insertions(+)
 create mode 100644 meta-arm/recipes-security/optee/optee-test/0001-Suppress-new-gcc-15-Wunterminated-string-initializat.patch
meta-arm/recipes-security/optee/optee-test/0001-Suppress-new-gcc-15-Wunterminated-string-initializat.patch new file +69 -0
new file mode 100644
index 00000000..0f52f3d6
@@ -0,0 +1,69 @@
+From a8e58203dcb4c13ee340259cd2692202ac8414d1 Mon Sep 17 00:00:00 2001
+From: Denys Dmytriyenko <[email protected]>
+Date: Tue, 6 May 2025 21:35:55 -0400
+Subject: [PATCH] Suppress new gcc-15 -Wunterminated-string-initialization
+
+GCC 15 now warns when character arrays are being initialized by strings
+and terminating NUL character doesn't fit. GCC 15.1 also allows marking
+such arrays with nonstring attribute to suppress the warning. W/o such
+attribute, the warning becomes error due to the global -Werror. Add the
+attribute accordingly.
+
+Fixes these errors:
+
+| ./regression_4000_data.h:7919:9: error: initializer-string for array of 'unsigned char' truncates NUL terminator but destination lacks 'nonstring' attribute (20 chars into 19 available) [-Werror=unterminated-string-initialization]
+|  7919 |         "encryption standard";
+|       |         ^~~~~~~~~~~~~~~~~~~~~
+| ./regression_4000_data.h:8387:9: error: initializer-string for array of 'unsigned char' truncates NUL terminator but destination lacks 'nonstring' attribute (113 chars into 112 available) [-Werror=unterminated-string-initialization]
+|  8387 |         "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomn"
+|       |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+| ./regression_4000.c:1295:47: error: initializer-string for array of 'unsigned char' truncates NUL terminator but destination lacks 'nonstring' attribute (4 chars into 3 available) [-Werror=unterminated-string-initialization]
+|  1295 | static const uint8_t hash_data_sm3_a1_in[3] = "abc";
+|       |                                               ^~~~~
+
+Upstream-Status: Pending
+
+Signed-off-by: Denys Dmytriyenko <[email protected]>
+---
+ host/xtest/regression_4000.c      | 2 +-
+ host/xtest/regression_4000_data.h | 4 ++--
+ 2 files changed, 3 insertions(+), 3 deletions(-)
+
+diff --git a/host/xtest/regression_4000.c b/host/xtest/regression_4000.c
+index 3aa15be..46e6f8e 100644
+--- a/host/xtest/regression_4000.c
++++ b/host/xtest/regression_4000.c
+@@ -1292,7 +1292,7 @@ static const uint8_t hash_data_shake256_out2[] = {
+  * https://tools.ietf.org/html/draft-sca-cfrg-sm3-02
+  * Appendix A.1
+  */
+-static const uint8_t hash_data_sm3_a1_in[3] = "abc";
++static const uint8_t hash_data_sm3_a1_in[3] __attribute__((nonstring)) = "abc";
+ 
+ static const uint8_t hash_data_sm3_a1_out[] = {
+ 	0x66, 0xc7, 0xf0, 0xf4, 0x62, 0xee, 0xed, 0xd9,
+diff --git a/host/xtest/regression_4000_data.h b/host/xtest/regression_4000_data.h
+index 0881ac3..eb101b2 100644
+--- a/host/xtest/regression_4000_data.h
++++ b/host/xtest/regression_4000_data.h
+@@ -7914,7 +7914,7 @@ static struct derive_key_ecdh_t {
+ };
+ 
+ /* G/MT 0003 (SM2) Part 5 Annex C.2 - encryption/decryption */
+-static const uint8_t gmt_0003_part5_c2_sm2_testvector_ptx[19] =
++static const uint8_t gmt_0003_part5_c2_sm2_testvector_ptx[19] __attribute__((nonstring)) =
+ /* M */
+ 	"encryption standard";
+ static const uint8_t gmt_0003_part5_c2_sm2_testvector_private[] = {
+@@ -8383,7 +8383,7 @@ static const uint8_t mac_data_sha3_512_out1[] = {
+  * GM/T 0042-2015
+  * Section D.3 Test vector 1
+  */
+-static const uint8_t mac_data_sm3_d31_in[112] =
++static const uint8_t mac_data_sm3_d31_in[112] __attribute__((nonstring)) =
+ 	"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomn"
+ 	"opnopqabcdbcdecdefdefgefghfghighijhijkijkljklmklmn"
+ 	"lmnomnopnopq";
+-- 
+2.25.1
+
meta-arm/recipes-security/optee/optee-test_4.4.0.bb +1 -0
index d514c82c..80df523d 100644
@@ -5,6 +5,7 @@ SRCREV = "695231ef8987866663a9ed5afd8f77d1bae3dc08"
 
 LIC_FILES_CHKSUM = "file://LICENSE.md;md5=a8fa504109e4cd7ea575bc49ea4be560"
 
+SRC_URI += "file://0001-Suppress-new-gcc-15-Wunterminated-string-initializat.patch"
 
 # Include ffa_spmc test group if the SPMC test is enabled.
 # Supported after op-tee v3.20
Signature · 1 line
2.25.1
#1 lore raw

Hi,

Quoted 33 lines · Denys Dmytriyenko via lists.yoctoproject.org

From: Denys Dmytriyenko <[email protected]>

Mark corresponding arrays with nonstring attribute to suppress the new gcc-15 warning -Wunterminated-string-initialization that becomes an error due to the global -Werror.

---
 ...-15-Wunterminated-string-initializat.patch | 69 +++++++++++++++++++
 .../optee/optee-test_4.4.0.bb                 |  1 +
 2 files changed, 70 insertions(+)
 create mode 100644 meta-arm/recipes-security/optee/optee-test/0001-Suppress-new-gcc-15-Wunterminated-string-initializat.patch
meta-arm/recipes-security/optee/optee-test/0001-Suppress-new-gcc-15-Wunterminated-string-initializat.patch new file +14 -0
new file mode 100644
index 00000000..0f52f3d6
@@ -0,0 +1,69 @@
+From a8e58203dcb4c13ee340259cd2692202ac8414d1 Mon Sep 17 00:00:00 2001
+From: Denys Dmytriyenko <[email protected]>
+Date: Tue, 6 May 2025 21:35:55 -0400
+Subject: [PATCH] Suppress new gcc-15 -Wunterminated-string-initialization
+
+GCC 15 now warns when character arrays are being initialized by strings
+and terminating NUL character doesn't fit. GCC 15.1 also allows marking
+such arrays with nonstring attribute to suppress the warning. W/o such
+attribute, the warning becomes error due to the global -Werror. Add the
+attribute accordingly.
+
+Fixes these errors:
+
+| ./regression_4000_data.h:7919:9: error: initializer-string for array of 'unsigned char' truncates NUL terminator but destination lacks 'nonstring' attribute (20 chars into 19 available) [-Werror=unterminated-string-initialization]

meta-arm/recipes-security/optee/optee-test/0001-Suppress-new-gcc-15-Wunterminated-string-initializat.patch line 24

Quoted 10 lines
meta-arm/recipes-security/optee/optee-test/0001-Suppress-new-gcc-15-Wunterminated-string-initializat.patch new file +10 -0
+|  7919 |         "encryption standard";
+|       |         ^~~~~~~~~~~~~~~~~~~~~
+| ./regression_4000_data.h:8387:9: error: initializer-string for array of 'unsigned char' truncates NUL terminator but destination lacks 'nonstring' attribute (113 chars into 112 available) [-Werror=unterminated-string-initialization]
+|  8387 |         "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomn"
+|       |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+| ./regression_4000.c:1295:47: error: initializer-string for array of 'unsigned char' truncates NUL terminator but destination lacks 'nonstring' attribute (4 chars into 3 available) [-Werror=unterminated-string-initialization]
+|  1295 | static const uint8_t hash_data_sm3_a1_in[3] = "abc";
+|       |                                               ^~~~~
+
+Upstream-Status: Pending

Thanks, this is the correct fix. Can you submit upstream? They react pretty fast there.

I still don't like -Werror as default since compiler and versions at distro/intregrator level may differ greatly from what upstream uses and supports.

Cheers,

-Mikko

Quoted 69 lines
meta-arm/recipes-security/optee/optee-test/0001-Suppress-new-gcc-15-Wunterminated-string-initializat.patch new file +44 -0
+Signed-off-by: Denys Dmytriyenko <[email protected]>
+---
+ host/xtest/regression_4000.c      | 2 +-
+ host/xtest/regression_4000_data.h | 4 ++--
+ 2 files changed, 3 insertions(+), 3 deletions(-)
+
+diff --git a/host/xtest/regression_4000.c b/host/xtest/regression_4000.c
+index 3aa15be..46e6f8e 100644
+--- a/host/xtest/regression_4000.c
++++ b/host/xtest/regression_4000.c
+@@ -1292,7 +1292,7 @@ static const uint8_t hash_data_shake256_out2[] = {
+  * https://tools.ietf.org/html/draft-sca-cfrg-sm3-02
+  * Appendix A.1
+  */
+-static const uint8_t hash_data_sm3_a1_in[3] = "abc";
++static const uint8_t hash_data_sm3_a1_in[3] __attribute__((nonstring)) = "abc";
+ 
+ static const uint8_t hash_data_sm3_a1_out[] = {
+ 	0x66, 0xc7, 0xf0, 0xf4, 0x62, 0xee, 0xed, 0xd9,
+diff --git a/host/xtest/regression_4000_data.h b/host/xtest/regression_4000_data.h
+index 0881ac3..eb101b2 100644
+--- a/host/xtest/regression_4000_data.h
++++ b/host/xtest/regression_4000_data.h
+@@ -7914,7 +7914,7 @@ static struct derive_key_ecdh_t {
+ };
+ 
+ /* G/MT 0003 (SM2) Part 5 Annex C.2 - encryption/decryption */
+-static const uint8_t gmt_0003_part5_c2_sm2_testvector_ptx[19] =
++static const uint8_t gmt_0003_part5_c2_sm2_testvector_ptx[19] __attribute__((nonstring)) =
+ /* M */
+ 	"encryption standard";
+ static const uint8_t gmt_0003_part5_c2_sm2_testvector_private[] = {
+@@ -8383,7 +8383,7 @@ static const uint8_t mac_data_sha3_512_out1[] = {
+  * GM/T 0042-2015
+  * Section D.3 Test vector 1
+  */
+-static const uint8_t mac_data_sm3_d31_in[112] =
++static const uint8_t mac_data_sm3_d31_in[112] __attribute__((nonstring)) =
+ 	"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomn"
+ 	"opnopqabcdbcdecdefdefgefghfghighijhijkijkljklmklmn"
+ 	"lmnomnopnopq";
+-- 
+2.25.1
+
meta-arm/recipes-security/optee/optee-test_4.4.0.bb +1 -0
index d514c82c..80df523d 100644
@@ -5,6 +5,7 @@ SRCREV = "695231ef8987866663a9ed5afd8f77d1bae3dc08"
 
 LIC_FILES_CHKSUM = "file://LICENSE.md;md5=a8fa504109e4cd7ea575bc49ea4be560"
 
+SRC_URI += "file://0001-Suppress-new-gcc-15-Wunterminated-string-initializat.patch"
 
 # Include ffa_spmc test group if the SPMC test is enabled.
 # Supported after op-tee v3.20
Signature · 11 lines
2.25.1



-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#6488): https://lists.yoctoproject.org/g/meta-arm/message/6488
Mute This Topic: https://lists.yoctoproject.org/mt/112661556/7159507
Group Owner: [email protected]
Unsubscribe: https://lists.yoctoproject.org/g/meta-arm/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-
#2 lore raw
Quoted 41 lines · Mikko Rapeli

Hi,

Quoted 38 lines · Denys Dmytriyenko via lists.yoctoproject.org

From: Denys Dmytriyenko <[email protected]>

Mark corresponding arrays with nonstring attribute to suppress the new gcc-15 warning -Wunterminated-string-initialization that becomes an error due to the global -Werror.

---
 ...-15-Wunterminated-string-initializat.patch | 69 +++++++++++++++++++
 .../optee/optee-test_4.4.0.bb                 |  1 +
 2 files changed, 70 insertions(+)
 create mode 100644 meta-arm/recipes-security/optee/optee-test/0001-Suppress-new-gcc-15-Wunterminated-string-initializat.patch
meta-arm/recipes-security/optee/optee-test/0001-Suppress-new-gcc-15-Wunterminated-string-initializat.patch new file +19 -0
new file mode 100644
index 00000000..0f52f3d6
@@ -0,0 +1,69 @@
+From a8e58203dcb4c13ee340259cd2692202ac8414d1 Mon Sep 17 00:00:00 2001
+From: Denys Dmytriyenko <[email protected]>
+Date: Tue, 6 May 2025 21:35:55 -0400
+Subject: [PATCH] Suppress new gcc-15 -Wunterminated-string-initialization
+
+GCC 15 now warns when character arrays are being initialized by strings
+and terminating NUL character doesn't fit. GCC 15.1 also allows marking
+such arrays with nonstring attribute to suppress the warning. W/o such
+attribute, the warning becomes error due to the global -Werror. Add the
+attribute accordingly.
+
+Fixes these errors:
+
+| ./regression_4000_data.h:7919:9: error: initializer-string for array of 'unsigned char' truncates NUL terminator but destination lacks 'nonstring' attribute (20 chars into 19 available) [-Werror=unterminated-string-initialization]
+|  7919 |         "encryption standard";
+|       |         ^~~~~~~~~~~~~~~~~~~~~
+| ./regression_4000_data.h:8387:9: error: initializer-string for array of 'unsigned char' truncates NUL terminator but destination lacks 'nonstring' attribute (113 chars into 112 available) [-Werror=unterminated-string-initialization]
+|  8387 |         "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomn"
+|       |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Quoted 8 lines

meta-arm/recipes-security/optee/optee-test/0001-Suppress-new-gcc-15-Wunterminated-string-initializat.patch line 24

Quoted 5 lines
meta-arm/recipes-security/optee/optee-test/0001-Suppress-new-gcc-15-Wunterminated-string-initializat.patch new file +5 -0
+| ./regression_4000.c:1295:47: error: initializer-string for array of 'unsigned char' truncates NUL terminator but destination lacks 'nonstring' attribute (4 chars into 3 available) [-Werror=unterminated-string-initialization]
+|  1295 | static const uint8_t hash_data_sm3_a1_in[3] = "abc";
+|       |                                               ^~~~~
+
+Upstream-Status: Pending

Thanks, this is the correct fix. Can you submit upstream? They react pretty fast there.

Already did.

Upstream-Status: Submitted [https://github.com/OP-TEE/optee_test/pull/796]

Quoted 66 lines

I still don't like -Werror as default since compiler and versions at distro/intregrator level may differ greatly from what upstream uses and supports.

Cheers,

-Mikko

Quoted 58 lines
meta-arm/recipes-security/optee/optee-test/0001-Suppress-new-gcc-15-Wunterminated-string-initializat.patch new file +44 -0
+Signed-off-by: Denys Dmytriyenko <[email protected]>
+---
+ host/xtest/regression_4000.c      | 2 +-
+ host/xtest/regression_4000_data.h | 4 ++--
+ 2 files changed, 3 insertions(+), 3 deletions(-)
+
+diff --git a/host/xtest/regression_4000.c b/host/xtest/regression_4000.c
+index 3aa15be..46e6f8e 100644
+--- a/host/xtest/regression_4000.c
++++ b/host/xtest/regression_4000.c
+@@ -1292,7 +1292,7 @@ static const uint8_t hash_data_shake256_out2[] = {
+  * https://tools.ietf.org/html/draft-sca-cfrg-sm3-02
+  * Appendix A.1
+  */
+-static const uint8_t hash_data_sm3_a1_in[3] = "abc";
++static const uint8_t hash_data_sm3_a1_in[3] __attribute__((nonstring)) = "abc";
+ 
+ static const uint8_t hash_data_sm3_a1_out[] = {
+ 	0x66, 0xc7, 0xf0, 0xf4, 0x62, 0xee, 0xed, 0xd9,
+diff --git a/host/xtest/regression_4000_data.h b/host/xtest/regression_4000_data.h
+index 0881ac3..eb101b2 100644
+--- a/host/xtest/regression_4000_data.h
++++ b/host/xtest/regression_4000_data.h
+@@ -7914,7 +7914,7 @@ static struct derive_key_ecdh_t {
+ };
+ 
+ /* G/MT 0003 (SM2) Part 5 Annex C.2 - encryption/decryption */
+-static const uint8_t gmt_0003_part5_c2_sm2_testvector_ptx[19] =
++static const uint8_t gmt_0003_part5_c2_sm2_testvector_ptx[19] __attribute__((nonstring)) =
+ /* M */
+ 	"encryption standard";
+ static const uint8_t gmt_0003_part5_c2_sm2_testvector_private[] = {
+@@ -8383,7 +8383,7 @@ static const uint8_t mac_data_sha3_512_out1[] = {
+  * GM/T 0042-2015
+  * Section D.3 Test vector 1
+  */
+-static const uint8_t mac_data_sm3_d31_in[112] =
++static const uint8_t mac_data_sm3_d31_in[112] __attribute__((nonstring)) =
+ 	"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomn"
+ 	"opnopqabcdbcdecdefdefgefghfghighijhijkijkljklmklmn"
+ 	"lmnomnopnopq";
+-- 
+2.25.1
+
meta-arm/recipes-security/optee/optee-test_4.4.0.bb +1 -0
index d514c82c..80df523d 100644
@@ -5,6 +5,7 @@ SRCREV = "695231ef8987866663a9ed5afd8f77d1bae3dc08"
 
 LIC_FILES_CHKSUM = "file://LICENSE.md;md5=a8fa504109e4cd7ea575bc49ea4be560"
 
+SRC_URI += "file://0001-Suppress-new-gcc-15-Wunterminated-string-initializat.patch"
 
 # Include ffa_spmc test group if the SPMC test is enabled.
 # Supported after op-tee v3.20
Signature · 1 line
2.25.1