Skip to content

Commit c12cb52

Browse files
authored
Merge pull request #239 from AndrzejKurek/psa-its-file-fixes
Remove a potential call to fwrite with null buffer. Add UBsan testing
2 parents 8269077 + f094b53 commit c12cb52

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ if(CMAKE_COMPILER_IS_GNU)
137137
set(CMAKE_C_FLAGS_RELEASE "-O2")
138138
set(CMAKE_C_FLAGS_DEBUG "-O0 -g3")
139139
set(CMAKE_C_FLAGS_COVERAGE "-O0 -g3 --coverage")
140-
set(CMAKE_C_FLAGS_ASAN "-Werror -fsanitize=address -fno-common -O3")
141-
set(CMAKE_C_FLAGS_ASANDBG "-Werror -fsanitize=address -fno-common -O1 -g3 -fno-omit-frame-pointer -fno-optimize-sibling-calls ")
140+
set(CMAKE_C_FLAGS_ASAN "-Werror -fsanitize=address -fno-common -fsanitize=undefined -fno-sanitize-recover=all -O3")
141+
set(CMAKE_C_FLAGS_ASANDBG "-Werror -fsanitize=address -fno-common -fsanitize=undefined -fno-sanitize-recover=all -O1 -g3 -fno-omit-frame-pointer -fno-optimize-sibling-calls")
142142
set(CMAKE_C_FLAGS_CHECK "-Werror -Os")
143143
set(CMAKE_C_FLAGS_CHECKFULL "${CMAKE_C_FLAGS_CHECK} -Wcast-qual")
144144
endif(CMAKE_COMPILER_IS_GNU)
@@ -149,7 +149,7 @@ if(CMAKE_COMPILER_IS_CLANG)
149149
set(CMAKE_C_FLAGS_DEBUG "-O0 -g3")
150150
set(CMAKE_C_FLAGS_COVERAGE "-O0 -g3 --coverage")
151151
set(CMAKE_C_FLAGS_ASAN "-Werror -fsanitize=address -fno-common -fsanitize=undefined -fno-sanitize-recover=all -O3")
152-
set(CMAKE_C_FLAGS_ASANDBG "-Werror -fsanitize=address -fno-common -fsanitize=undefined -fno-sanitize-recover=all -O1 -g3 -fno-omit-frame-pointer -fno-optimize-sibling-calls ")
152+
set(CMAKE_C_FLAGS_ASANDBG "-Werror -fsanitize=address -fno-common -fsanitize=undefined -fno-sanitize-recover=all -O1 -g3 -fno-omit-frame-pointer -fno-optimize-sibling-calls")
153153
set(CMAKE_C_FLAGS_MEMSAN "-Werror -fsanitize=memory -O3")
154154
set(CMAKE_C_FLAGS_MEMSANDBG "-Werror -fsanitize=memory -O1 -g3 -fno-omit-frame-pointer -fno-optimize-sibling-calls -fsanitize-memory-track-origins=2")
155155
set(CMAKE_C_FLAGS_CHECK "-Werror -Os")

library/psa_its_file.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,12 @@ psa_status_t psa_its_set( psa_storage_uid_t uid,
214214
n = fwrite( &header, 1, sizeof( header ), stream );
215215
if( n != sizeof( header ) )
216216
goto exit;
217-
n = fwrite( p_data, 1, data_length, stream );
218-
if( n != data_length )
219-
goto exit;
217+
if( data_length != 0 )
218+
{
219+
n = fwrite( p_data, 1, data_length, stream );
220+
if( n != data_length )
221+
goto exit;
222+
}
220223
status = PSA_SUCCESS;
221224

222225
exit:

tests/scripts/all.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ component_test_no_use_psa_crypto_full_cmake_asan() {
701701
# full minus MBEDTLS_USE_PSA_CRYPTO: run the same set of tests as basic-build-test.sh
702702
msg "build: cmake, full config + MBEDTLS_USE_PSA_CRYPTO, ASan"
703703
scripts/config.pl full
704-
scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
704+
scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
705705
scripts/config.pl set MBEDTLS_ECP_RESTARTABLE # not using PSA, so enable restartable ECC
706706
scripts/config.pl set MBEDTLS_PSA_CRYPTO_C
707707
scripts/config.pl unset MBEDTLS_USE_PSA_CRYPTO

0 commit comments

Comments
 (0)