From 5b84ae14e9f09aae0597d1ab5bd3ed356159f9ba Mon Sep 17 00:00:00 2001 From: Felix Conway Date: Thu, 12 Jun 2025 11:28:56 +0100 Subject: [PATCH] Replace __attribute__((nonstring)) with macro MBEDTLS_ATTRIBUTE_UNTERMINATED_STRING This macro applies __attribute__((nonstring)) when using a compiler that supports it Signed-off-by: Felix Conway --- library/ssl_tls13_keys.c | 2 +- library/ssl_tls13_keys.h | 2 +- .../psasim/src/aut_psa_aead_encrypt_decrypt.c | 3 ++- .../psasim/src/aut_psa_cipher_encrypt_decrypt.c | 3 ++- tests/suites/test_suite_ssl_decrypt.function | 2 +- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/library/ssl_tls13_keys.c b/library/ssl_tls13_keys.c index 51afb044cc..865e02c2dc 100644 --- a/library/ssl_tls13_keys.c +++ b/library/ssl_tls13_keys.c @@ -81,7 +81,7 @@ struct mbedtls_ssl_tls13_labels_struct const mbedtls_ssl_tls13_labels = */ /* We need to tell the compiler that we meant to leave out the null character. */ -static const char tls13_label_prefix[6] __attribute__ ((nonstring)) = "tls13 "; +static const char tls13_label_prefix[6] MBEDTLS_ATTRIBUTE_UNTERMINATED_STRING = "tls13 "; #define SSL_TLS1_3_KEY_SCHEDULE_HKDF_LABEL_LEN(label_len, context_len) \ (2 /* expansion length */ \ diff --git a/library/ssl_tls13_keys.h b/library/ssl_tls13_keys.h index f6d02b522a..1509e9a4d4 100644 --- a/library/ssl_tls13_keys.h +++ b/library/ssl_tls13_keys.h @@ -42,7 +42,7 @@ /* We need to tell the compiler that we meant to leave out the null character. */ #define MBEDTLS_SSL_TLS1_3_LABEL(name, string) \ - const unsigned char name [sizeof(string) - 1] __attribute__ ((nonstring)); + const unsigned char name [sizeof(string) - 1] MBEDTLS_ATTRIBUTE_UNTERMINATED_STRING; union mbedtls_ssl_tls13_labels_union { MBEDTLS_SSL_TLS1_3_LABEL_LIST diff --git a/tests/psa-client-server/psasim/src/aut_psa_aead_encrypt_decrypt.c b/tests/psa-client-server/psasim/src/aut_psa_aead_encrypt_decrypt.c index 83cd3c00dd..313397bbcd 100644 --- a/tests/psa-client-server/psasim/src/aut_psa_aead_encrypt_decrypt.c +++ b/tests/psa-client-server/psasim/src/aut_psa_aead_encrypt_decrypt.c @@ -26,7 +26,8 @@ int psa_aead_encrypt_decrypt_main(void) uint8_t decrypt[BUFFER_SIZE] = { 0 }; const uint8_t plaintext[] = "Hello World!"; /* We need to tell the compiler that we meant to leave out the null character. */ - const uint8_t key_bytes[32] __attribute__ ((nonstring)) = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; + const uint8_t key_bytes[32] MBEDTLS_ATTRIBUTE_UNTERMINATED_STRING = + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; uint8_t nonce[PSA_AEAD_NONCE_LENGTH(PSA_KEY_TYPE_AES, PSA_ALG_CCM)]; size_t nonce_length = sizeof(nonce); size_t ciphertext_length; diff --git a/tests/psa-client-server/psasim/src/aut_psa_cipher_encrypt_decrypt.c b/tests/psa-client-server/psasim/src/aut_psa_cipher_encrypt_decrypt.c index 22d0bfb0f0..30b6982e04 100644 --- a/tests/psa-client-server/psasim/src/aut_psa_cipher_encrypt_decrypt.c +++ b/tests/psa-client-server/psasim/src/aut_psa_cipher_encrypt_decrypt.c @@ -26,7 +26,8 @@ int psa_cipher_encrypt_decrypt_main(void) uint8_t encrypt[BUFFER_SIZE] = { 0 }; uint8_t decrypt[BUFFER_SIZE] = { 0 }; /* We need to tell the compiler that we meant to leave out the null character. */ - const uint8_t key_bytes[32] __attribute__ ((nonstring)) = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; + const uint8_t key_bytes[32] MBEDTLS_ATTRIBUTE_UNTERMINATED_STRING = + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; size_t encrypted_length; size_t decrypted_length; diff --git a/tests/suites/test_suite_ssl_decrypt.function b/tests/suites/test_suite_ssl_decrypt.function index 72824163a5..37265def88 100644 --- a/tests/suites/test_suite_ssl_decrypt.function +++ b/tests/suites/test_suite_ssl_decrypt.function @@ -38,7 +38,7 @@ void ssl_decrypt_null(int hash_id) MBEDTLS_SSL_TRANSPORT_STREAM, version); /* We need to tell the compiler that we meant to leave out the null character. */ - const char sample_plaintext[3] __attribute__ ((nonstring)) = "ABC"; + const char sample_plaintext[3] MBEDTLS_ATTRIBUTE_UNTERMINATED_STRING = "ABC"; mbedtls_ssl_context ssl; mbedtls_ssl_init(&ssl); uint8_t *buf = NULL;