Add guards for mbedtls_psa_crypto_free()

Signed-off-by: Przemek Stekiel <przemyslaw.stekiel@mobica.com>
This commit is contained in:
Przemek Stekiel 2023-04-19 13:47:43 +02:00
parent 774f9debf2
commit 758aef60c5
32 changed files with 71 additions and 4 deletions

View file

@ -182,7 +182,9 @@ exit:
mbedtls_ctr_drbg_free(&ctr_drbg); mbedtls_ctr_drbg_free(&ctr_drbg);
mbedtls_ssl_config_free(&conf); mbedtls_ssl_config_free(&conf);
mbedtls_ssl_free(&ssl); mbedtls_ssl_free(&ssl);
#if defined(MBEDTLS_USE_PSA_CRYPTO)
mbedtls_psa_crypto_free(); mbedtls_psa_crypto_free();
#endif /* MBEDTLS_USE_PSA_CRYPTO */
#else #else
(void) Data; (void) Data;

View file

@ -126,7 +126,9 @@ exit:
mbedtls_ctr_drbg_free(&ctr_drbg); mbedtls_ctr_drbg_free(&ctr_drbg);
mbedtls_ssl_config_free(&conf); mbedtls_ssl_config_free(&conf);
mbedtls_ssl_free(&ssl); mbedtls_ssl_free(&ssl);
#if defined(MBEDTLS_USE_PSA_CRYPTO)
mbedtls_psa_crypto_free(); mbedtls_psa_crypto_free();
#endif /* MBEDTLS_USE_PSA_CRYPTO */
#else #else
(void) Data; (void) Data;

View file

@ -171,7 +171,9 @@ exit:
mbedtls_ctr_drbg_free(&ctr_drbg); mbedtls_ctr_drbg_free(&ctr_drbg);
mbedtls_ssl_config_free(&conf); mbedtls_ssl_config_free(&conf);
mbedtls_ssl_free(&ssl); mbedtls_ssl_free(&ssl);
#if defined(MBEDTLS_USE_PSA_CRYPTO)
mbedtls_psa_crypto_free(); mbedtls_psa_crypto_free();
#endif /* MBEDTLS_USE_PSA_CRYPTO */
#else #else
(void) Data; (void) Data;

View file

@ -94,7 +94,9 @@ exit:
mbedtls_entropy_free(&entropy); mbedtls_entropy_free(&entropy);
mbedtls_ctr_drbg_free(&ctr_drbg); mbedtls_ctr_drbg_free(&ctr_drbg);
mbedtls_pk_free(&pk); mbedtls_pk_free(&pk);
#if defined(MBEDTLS_USE_PSA_CRYPTO)
mbedtls_psa_crypto_free(); mbedtls_psa_crypto_free();
#endif /* MBEDTLS_USE_PSA_CRYPTO */
#else #else
(void) Data; (void) Data;
(void) Size; (void) Size;

View file

@ -72,9 +72,11 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
abort(); abort();
} }
} }
#if defined(MBEDTLS_USE_PSA_CRYPTO)
exit: exit:
mbedtls_pk_free(&pk);
mbedtls_psa_crypto_free(); mbedtls_psa_crypto_free();
#endif /* MBEDTLS_USE_PSA_CRYPTO */
mbedtls_pk_free(&pk);
#else #else
(void) Data; (void) Data;
(void) Size; (void) Size;

View file

@ -26,9 +26,12 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
((void) ret); ((void) ret);
((void) buf); ((void) buf);
#endif /* !MBEDTLS_X509_REMOVE_INFO */ #endif /* !MBEDTLS_X509_REMOVE_INFO */
#if defined(MBEDTLS_USE_PSA_CRYPTO)
exit: exit:
mbedtls_x509_crl_free(&crl);
mbedtls_psa_crypto_free(); mbedtls_psa_crypto_free();
#endif /* MBEDTLS_USE_PSA_CRYPTO */
mbedtls_x509_crl_free(&crl);
#else #else
(void) Data; (void) Data;
(void) Size; (void) Size;

View file

@ -26,9 +26,12 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
((void) ret); ((void) ret);
((void) buf); ((void) buf);
#endif /* !MBEDTLS_X509_REMOVE_INFO */ #endif /* !MBEDTLS_X509_REMOVE_INFO */
#if defined(MBEDTLS_USE_PSA_CRYPTO)
exit: exit:
mbedtls_x509_crt_free(&crt);
mbedtls_psa_crypto_free(); mbedtls_psa_crypto_free();
#endif /* MBEDTLS_USE_PSA_CRYPTO */
mbedtls_x509_crt_free(&crt);
#else #else
(void) Data; (void) Data;
(void) Size; (void) Size;

View file

@ -26,9 +26,12 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
((void) ret); ((void) ret);
((void) buf); ((void) buf);
#endif /* !MBEDTLS_X509_REMOVE_INFO */ #endif /* !MBEDTLS_X509_REMOVE_INFO */
#if defined(MBEDTLS_USE_PSA_CRYPTO)
exit: exit:
mbedtls_x509_csr_free(&csr);
mbedtls_psa_crypto_free(); mbedtls_psa_crypto_free();
#endif /* MBEDTLS_USE_PSA_CRYPTO */
mbedtls_x509_csr_free(&csr);
#else #else
(void) Data; (void) Data;
(void) Size; (void) Size;

View file

@ -416,7 +416,9 @@ exit:
mbedtls_pk_free(&key); mbedtls_pk_free(&key);
mbedtls_ctr_drbg_free(&ctr_drbg); mbedtls_ctr_drbg_free(&ctr_drbg);
mbedtls_entropy_free(&entropy); mbedtls_entropy_free(&entropy);
#if defined(MBEDTLS_USE_PSA_CRYPTO)
mbedtls_psa_crypto_free(); mbedtls_psa_crypto_free();
#endif /* MBEDTLS_USE_PSA_CRYPTO */
mbedtls_exit(exit_code); mbedtls_exit(exit_code);
} }

View file

@ -315,7 +315,9 @@ cleanup:
mbedtls_ctr_drbg_free(&ctr_drbg); mbedtls_ctr_drbg_free(&ctr_drbg);
mbedtls_entropy_free(&entropy); mbedtls_entropy_free(&entropy);
mbedtls_pk_free(&pk); mbedtls_pk_free(&pk);
#if defined(MBEDTLS_USE_PSA_CRYPTO)
mbedtls_psa_crypto_free(); mbedtls_psa_crypto_free();
#endif /* MBEDTLS_USE_PSA_CRYPTO */
mbedtls_mpi_free(&N); mbedtls_mpi_free(&P); mbedtls_mpi_free(&Q); mbedtls_mpi_free(&N); mbedtls_mpi_free(&P); mbedtls_mpi_free(&Q);
mbedtls_mpi_free(&D); mbedtls_mpi_free(&E); mbedtls_mpi_free(&DP); mbedtls_mpi_free(&D); mbedtls_mpi_free(&E); mbedtls_mpi_free(&DP);
mbedtls_mpi_free(&DQ); mbedtls_mpi_free(&QP); mbedtls_mpi_free(&DQ); mbedtls_mpi_free(&QP);

View file

@ -431,7 +431,9 @@ exit:
mbedtls_ctr_drbg_free(&ctr_drbg); mbedtls_ctr_drbg_free(&ctr_drbg);
mbedtls_entropy_free(&entropy); mbedtls_entropy_free(&entropy);
#if defined(MBEDTLS_USE_PSA_CRYPTO)
mbedtls_psa_crypto_free(); mbedtls_psa_crypto_free();
#endif /* MBEDTLS_USE_PSA_CRYPTO */
mbedtls_exit(exit_code); mbedtls_exit(exit_code);
} }

View file

@ -148,7 +148,9 @@ exit:
mbedtls_pk_free(&pk); mbedtls_pk_free(&pk);
mbedtls_entropy_free(&entropy); mbedtls_entropy_free(&entropy);
mbedtls_ctr_drbg_free(&ctr_drbg); mbedtls_ctr_drbg_free(&ctr_drbg);
#if defined(MBEDTLS_USE_PSA_CRYPTO)
mbedtls_psa_crypto_free(); mbedtls_psa_crypto_free();
#endif /* MBEDTLS_USE_PSA_CRYPTO */
#if defined(MBEDTLS_ERROR_C) #if defined(MBEDTLS_ERROR_C)
if (exit_code != MBEDTLS_EXIT_SUCCESS) { if (exit_code != MBEDTLS_EXIT_SUCCESS) {

View file

@ -149,7 +149,9 @@ exit:
mbedtls_pk_free(&pk); mbedtls_pk_free(&pk);
mbedtls_entropy_free(&entropy); mbedtls_entropy_free(&entropy);
mbedtls_ctr_drbg_free(&ctr_drbg); mbedtls_ctr_drbg_free(&ctr_drbg);
#if defined(MBEDTLS_USE_PSA_CRYPTO)
mbedtls_psa_crypto_free(); mbedtls_psa_crypto_free();
#endif /* MBEDTLS_USE_PSA_CRYPTO */
#if defined(MBEDTLS_ERROR_C) #if defined(MBEDTLS_ERROR_C)
if (exit_code != MBEDTLS_EXIT_SUCCESS) { if (exit_code != MBEDTLS_EXIT_SUCCESS) {

View file

@ -149,7 +149,9 @@ exit:
mbedtls_pk_free(&pk); mbedtls_pk_free(&pk);
mbedtls_ctr_drbg_free(&ctr_drbg); mbedtls_ctr_drbg_free(&ctr_drbg);
mbedtls_entropy_free(&entropy); mbedtls_entropy_free(&entropy);
#if defined(MBEDTLS_USE_PSA_CRYPTO)
mbedtls_psa_crypto_free(); mbedtls_psa_crypto_free();
#endif /* MBEDTLS_USE_PSA_CRYPTO */
#if defined(MBEDTLS_ERROR_C) #if defined(MBEDTLS_ERROR_C)
if (exit_code != MBEDTLS_EXIT_SUCCESS) { if (exit_code != MBEDTLS_EXIT_SUCCESS) {

View file

@ -123,7 +123,9 @@ int main(int argc, char *argv[])
exit: exit:
mbedtls_pk_free(&pk); mbedtls_pk_free(&pk);
#if defined(MBEDTLS_USE_PSA_CRYPTO)
mbedtls_psa_crypto_free(); mbedtls_psa_crypto_free();
#endif /* MBEDTLS_USE_PSA_CRYPTO */
#if defined(MBEDTLS_ERROR_C) #if defined(MBEDTLS_ERROR_C)
if (exit_code != MBEDTLS_EXIT_SUCCESS) { if (exit_code != MBEDTLS_EXIT_SUCCESS) {

View file

@ -162,7 +162,9 @@ exit:
mbedtls_pk_free(&pk); mbedtls_pk_free(&pk);
mbedtls_ctr_drbg_free(&ctr_drbg); mbedtls_ctr_drbg_free(&ctr_drbg);
mbedtls_entropy_free(&entropy); mbedtls_entropy_free(&entropy);
#if defined(MBEDTLS_USE_PSA_CRYPTO)
mbedtls_psa_crypto_free(); mbedtls_psa_crypto_free();
#endif /* MBEDTLS_USE_PSA_CRYPTO */
mbedtls_exit(exit_code); mbedtls_exit(exit_code);
} }

View file

@ -138,7 +138,9 @@ int main(int argc, char *argv[])
exit: exit:
mbedtls_pk_free(&pk); mbedtls_pk_free(&pk);
#if defined(MBEDTLS_USE_PSA_CRYPTO)
mbedtls_psa_crypto_free(); mbedtls_psa_crypto_free();
#endif /* MBEDTLS_USE_PSA_CRYPTO */
mbedtls_exit(exit_code); mbedtls_exit(exit_code);
} }

View file

@ -339,7 +339,9 @@ exit:
mbedtls_ssl_config_free(&conf); mbedtls_ssl_config_free(&conf);
mbedtls_ctr_drbg_free(&ctr_drbg); mbedtls_ctr_drbg_free(&ctr_drbg);
mbedtls_entropy_free(&entropy); mbedtls_entropy_free(&entropy);
#if defined(MBEDTLS_USE_PSA_CRYPTO)
mbedtls_psa_crypto_free(); mbedtls_psa_crypto_free();
#endif /* MBEDTLS_USE_PSA_CRYPTO */
/* Shell can not handle large exit numbers -> 1 for errors */ /* Shell can not handle large exit numbers -> 1 for errors */
if (ret < 0) { if (ret < 0) {

View file

@ -404,7 +404,9 @@ exit:
#endif #endif
mbedtls_ctr_drbg_free(&ctr_drbg); mbedtls_ctr_drbg_free(&ctr_drbg);
mbedtls_entropy_free(&entropy); mbedtls_entropy_free(&entropy);
#if defined(MBEDTLS_USE_PSA_CRYPTO)
mbedtls_psa_crypto_free(); mbedtls_psa_crypto_free();
#endif /* MBEDTLS_USE_PSA_CRYPTO */
/* Shell can not handle large exit numbers -> 1 for errors */ /* Shell can not handle large exit numbers -> 1 for errors */
if (ret < 0) { if (ret < 0) {

View file

@ -277,7 +277,9 @@ exit:
#if defined(MBEDTLS_X509_CRT_PARSE_C) #if defined(MBEDTLS_X509_CRT_PARSE_C)
mbedtls_x509_crt_free(&ca); mbedtls_x509_crt_free(&ca);
#endif #endif
#if defined(MBEDTLS_USE_PSA_CRYPTO)
mbedtls_psa_crypto_free(); mbedtls_psa_crypto_free();
#endif /* MBEDTLS_USE_PSA_CRYPTO */
mbedtls_exit(ret); mbedtls_exit(ret);
} }

View file

@ -289,7 +289,9 @@ exit:
mbedtls_ssl_config_free(&conf); mbedtls_ssl_config_free(&conf);
mbedtls_ctr_drbg_free(&ctr_drbg); mbedtls_ctr_drbg_free(&ctr_drbg);
mbedtls_entropy_free(&entropy); mbedtls_entropy_free(&entropy);
#if defined(MBEDTLS_USE_PSA_CRYPTO)
mbedtls_psa_crypto_free(); mbedtls_psa_crypto_free();
#endif /* MBEDTLS_USE_PSA_CRYPTO */
mbedtls_exit(exit_code); mbedtls_exit(exit_code);
} }

View file

@ -1011,7 +1011,9 @@ int main(int argc, char *argv[])
printf("Finished. No valid base64 code found\n"); printf("Finished. No valid base64 code found\n");
} }
#if defined(MBEDTLS_USE_PSA_CRYPTO)
mbedtls_psa_crypto_free(); mbedtls_psa_crypto_free();
#endif /* MBEDTLS_USE_PSA_CRYPTO */
return 0; return 0;
} }

View file

@ -381,7 +381,9 @@ exit:
mbedtls_ssl_config_free(&conf); mbedtls_ssl_config_free(&conf);
mbedtls_ctr_drbg_free(&ctr_drbg); mbedtls_ctr_drbg_free(&ctr_drbg);
mbedtls_entropy_free(&entropy); mbedtls_entropy_free(&entropy);
#if defined(MBEDTLS_USE_PSA_CRYPTO)
mbedtls_psa_crypto_free(); mbedtls_psa_crypto_free();
#endif /* MBEDTLS_USE_PSA_CRYPTO */
mbedtls_exit(exit_code); mbedtls_exit(exit_code);
} }

View file

@ -805,7 +805,9 @@ exit:
mbedtls_ssl_config_free(&conf); mbedtls_ssl_config_free(&conf);
mbedtls_ctr_drbg_free(&ctr_drbg); mbedtls_ctr_drbg_free(&ctr_drbg);
mbedtls_entropy_free(&entropy); mbedtls_entropy_free(&entropy);
#if defined(MBEDTLS_USE_PSA_CRYPTO)
mbedtls_psa_crypto_free(); mbedtls_psa_crypto_free();
#endif /* MBEDTLS_USE_PSA_CRYPTO */
mbedtls_exit(exit_code); mbedtls_exit(exit_code);
} }

View file

@ -488,7 +488,9 @@ exit:
#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) #if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
mbedtls_memory_buffer_alloc_free(); mbedtls_memory_buffer_alloc_free();
#endif #endif
#if defined(MBEDTLS_USE_PSA_CRYPTO)
mbedtls_psa_crypto_free(); mbedtls_psa_crypto_free();
#endif /* MBEDTLS_USE_PSA_CRYPTO */
mbedtls_exit(ret); mbedtls_exit(ret);
} }

View file

@ -362,7 +362,9 @@ exit:
#endif #endif
mbedtls_ctr_drbg_free(&ctr_drbg); mbedtls_ctr_drbg_free(&ctr_drbg);
mbedtls_entropy_free(&entropy); mbedtls_entropy_free(&entropy);
#if defined(MBEDTLS_USE_PSA_CRYPTO)
mbedtls_psa_crypto_free(); mbedtls_psa_crypto_free();
#endif /* MBEDTLS_USE_PSA_CRYPTO */
mbedtls_exit(ret); mbedtls_exit(ret);
} }

View file

@ -457,7 +457,9 @@ exit:
#endif #endif
mbedtls_ctr_drbg_free(&ctr_drbg); mbedtls_ctr_drbg_free(&ctr_drbg);
mbedtls_entropy_free(&entropy); mbedtls_entropy_free(&entropy);
#if defined(MBEDTLS_USE_PSA_CRYPTO)
mbedtls_psa_crypto_free(); mbedtls_psa_crypto_free();
#endif /* MBEDTLS_USE_PSA_CRYPTO */
mbedtls_exit(exit_code); mbedtls_exit(exit_code);
} }

View file

@ -469,7 +469,9 @@ exit:
mbedtls_pk_free(&key); mbedtls_pk_free(&key);
mbedtls_ctr_drbg_free(&ctr_drbg); mbedtls_ctr_drbg_free(&ctr_drbg);
mbedtls_entropy_free(&entropy); mbedtls_entropy_free(&entropy);
#if defined(MBEDTLS_USE_PSA_CRYPTO)
mbedtls_psa_crypto_free(); mbedtls_psa_crypto_free();
#endif /* MBEDTLS_USE_PSA_CRYPTO */
cur = opt.san_list; cur = opt.san_list;
while (cur != NULL) { while (cur != NULL) {

View file

@ -894,7 +894,9 @@ exit:
mbedtls_pk_free(&loaded_issuer_key); mbedtls_pk_free(&loaded_issuer_key);
mbedtls_ctr_drbg_free(&ctr_drbg); mbedtls_ctr_drbg_free(&ctr_drbg);
mbedtls_entropy_free(&entropy); mbedtls_entropy_free(&entropy);
#if defined(MBEDTLS_USE_PSA_CRYPTO)
mbedtls_psa_crypto_free(); mbedtls_psa_crypto_free();
#endif /* MBEDTLS_USE_PSA_CRYPTO */
mbedtls_exit(exit_code); mbedtls_exit(exit_code);
} }

View file

@ -134,7 +134,9 @@ usage:
exit: exit:
mbedtls_x509_crl_free(&crl); mbedtls_x509_crl_free(&crl);
#if defined(MBEDTLS_USE_PSA_CRYPTO)
mbedtls_psa_crypto_free(); mbedtls_psa_crypto_free();
#endif /* MBEDTLS_USE_PSA_CRYPTO */
mbedtls_exit(exit_code); mbedtls_exit(exit_code);
} }

View file

@ -196,7 +196,9 @@ int main(int argc, char *argv[])
exit_code = MBEDTLS_EXIT_SUCCESS; exit_code = MBEDTLS_EXIT_SUCCESS;
exit: exit:
#if defined(MBEDTLS_USE_PSA_CRYPTO)
mbedtls_psa_crypto_free(); mbedtls_psa_crypto_free();
#endif /* MBEDTLS_USE_PSA_CRYPTO */
mbedtls_exit(exit_code); mbedtls_exit(exit_code);
} }
#endif /* necessary configuration */ #endif /* necessary configuration */

View file

@ -134,7 +134,9 @@ usage:
exit: exit:
mbedtls_x509_csr_free(&csr); mbedtls_x509_csr_free(&csr);
#if defined(MBEDTLS_USE_PSA_CRYPTO)
mbedtls_psa_crypto_free(); mbedtls_psa_crypto_free();
#endif /* MBEDTLS_USE_PSA_CRYPTO */
mbedtls_exit(exit_code); mbedtls_exit(exit_code);
} }