Merge pull request #6998 from aditya-deshpande-arm/fix-example-programs-usage

Fix incorrect dispatch to USAGE in example programs, which causes uninitialized memory to be used
This commit is contained in:
Dave Rodgman 2023-02-06 09:53:50 +00:00 committed by GitHub
commit 94c9c96c94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 19 additions and 15 deletions

View File

@ -0,0 +1,4 @@
Bugfix
* Fix behavior of certain sample programs which could, when run with no
arguments, access uninitialized memory in some cases. Fixes #6700 (which
was found by TrustInSoft Analyzer during REDOCS'22) and #1120.

View File

@ -169,7 +169,7 @@ int main(int argc, char *argv[])
mbedtls_md_init(&md_ctx);
if (argc == 1) {
if (argc < 2) {
const int *list;
mbedtls_printf("print mode: generic_sum <mbedtls_md> <file> <file> ...\n");

View File

@ -71,7 +71,7 @@ int main(int argc, char **argv)
mbedtls_ctr_drbg_init(&ctr_drbg);
mbedtls_entropy_init(&entropy);
if (argc == 0) {
if (argc < 2) {
usage:
mbedtls_printf(USAGE);
goto exit;

View File

@ -200,7 +200,7 @@ int main(int argc, char *argv[])
mbedtls_ctr_drbg_init(&ctr_drbg);
memset(buf, 0, sizeof(buf));
if (argc == 0) {
if (argc < 2) {
usage:
mbedtls_printf(USAGE);
#if defined(MBEDTLS_ECP_C)

View File

@ -103,7 +103,7 @@ int main(int argc, char *argv[])
mbedtls_mpi_init(&D); mbedtls_mpi_init(&E); mbedtls_mpi_init(&DP);
mbedtls_mpi_init(&DQ); mbedtls_mpi_init(&QP);
if (argc == 0) {
if (argc < 2) {
usage:
mbedtls_printf(USAGE);
goto cleanup;

View File

@ -220,7 +220,7 @@ int main(int argc, char *argv[])
mbedtls_mpi_init(&D); mbedtls_mpi_init(&E); mbedtls_mpi_init(&DP);
mbedtls_mpi_init(&DQ); mbedtls_mpi_init(&QP);
if (argc == 0) {
if (argc < 2) {
usage:
mbedtls_printf(USAGE);
goto exit;

View File

@ -867,7 +867,7 @@ int main(int argc, char *argv[])
mbedtls_test_enable_insecure_external_rng();
#endif /* MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG */
if (argc == 0) {
if (argc < 2) {
usage:
if (ret == 0) {
ret = 1;

View File

@ -370,7 +370,7 @@ int main(int argc, char *argv[])
mbedtls_pk_init(&pkey);
mbedtls_ctr_drbg_init(&ctr_drbg);
if (argc == 0) {
if (argc < 2) {
usage:
mbedtls_printf(USAGE);

View File

@ -1633,7 +1633,7 @@ int main(int argc, char *argv[])
signal(SIGINT, term_handler);
#endif
if (argc == 0) {
if (argc < 2) {
usage:
if (ret == 0) {
ret = 1;

View File

@ -40,7 +40,7 @@ int main(int argc, char *argv[])
{
int i;
if (argc == 1 || strcmp(argv[1], "-h") == 0) {
if (argc < 2 || strcmp(argv[1], "-h") == 0) {
mbedtls_printf(USAGE, argv[0]);
return MBEDTLS_EXIT_FAILURE;
}

View File

@ -189,7 +189,7 @@ int main(int argc, char *argv[])
memset(buf, 0, sizeof(buf));
memset(der_buffer, 0, sizeof(der_buffer));
if (argc == 0) {
if (argc < 2) {
usage:
mbedtls_printf(USAGE);
goto exit;

View File

@ -161,7 +161,7 @@ int main(int argc, char *argv[])
memset(&cacrl, 0, sizeof(mbedtls_x509_crl));
#endif
if (argc == 0) {
if (argc < 2) {
usage:
mbedtls_printf(USAGE);
goto exit;

View File

@ -159,7 +159,7 @@ int main(int argc, char *argv[])
mbedtls_ctr_drbg_init(&ctr_drbg);
memset(buf, 0, sizeof(buf));
if (argc == 0) {
if (argc < 2) {
usage:
mbedtls_printf(USAGE);
goto exit;

View File

@ -329,7 +329,7 @@ int main(int argc, char *argv[])
memset(buf, 0, sizeof(buf));
memset(serial, 0, sizeof(serial));
if (argc == 0) {
if (argc < 2) {
usage:
mbedtls_printf(USAGE);
goto exit;

View File

@ -70,7 +70,7 @@ int main(int argc, char *argv[])
*/
mbedtls_x509_crl_init(&crl);
if (argc == 0) {
if (argc < 2) {
usage:
mbedtls_printf(USAGE);
goto exit;

View File

@ -70,7 +70,7 @@ int main(int argc, char *argv[])
*/
mbedtls_x509_csr_init(&csr);
if (argc == 0) {
if (argc < 2) {
usage:
mbedtls_printf(USAGE);
goto exit;