From ddebc49f286e3fa789fefd178604a7c213e8a159 Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Tue, 24 Oct 2017 22:16:34 +0100 Subject: [PATCH] Add gdb script to test mbedtls_zeroize() The gdb script loads the programs/test/zeroize program and feeds it as imput its own source code. Then sets a breakpoint just before the last program's return code and checks that every element in memory was zeroized. Otherwise it signals a failure and terminates. The test was added to all.sh. --- tests/scripts/all.sh | 2 +- tests/scripts/test_zeroize.gdb | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 tests/scripts/test_zeroize.gdb diff --git a/tests/scripts/all.sh b/tests/scripts/all.sh index 497a261c4..81ab2ca90 100755 --- a/tests/scripts/all.sh +++ b/tests/scripts/all.sh @@ -421,7 +421,7 @@ export GNUTLS_SERV="$GNUTLS_SERV" # Make sure the tools we need are available. check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$GNUTLS_CLI" "$GNUTLS_SERV" \ "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV" "doxygen" "dot" \ - "arm-none-eabi-gcc" "i686-w64-mingw32-gcc" + "arm-none-eabi-gcc" "i686-w64-mingw32-gcc" "gdb" if [ $RUN_ARMCC -ne 0 ]; then check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR" fi diff --git a/tests/scripts/test_zeroize.gdb b/tests/scripts/test_zeroize.gdb new file mode 100644 index 000000000..52b7cda7f --- /dev/null +++ b/tests/scripts/test_zeroize.gdb @@ -0,0 +1,25 @@ +set confirm off +file ./programs/test/zeroize +break zeroize.c:90 + +set args ./programs/test/zeroize.c +run + +set $i = 0 +set $len = sizeof(buf) +set $buf = buf + +if exit_code != 0 + echo The program did not terminate correctly\n + quit 1 +end + +while $i < $len + if $buf[$i++] != 0 + echo The buffer at was not zeroized\n + quit 1 + end +end + +echo The buffer was correctly zeroized\n +quit 0