Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion library/x509_crt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1744,7 +1744,7 @@ static int x509_info_cert_policies(char **buf, size_t *size,
/*
* Return an informational string about the certificate.
*/
#define MBEDTLS_BEFORE_COLON 18
#define MBEDTLS_BEFORE_COLON 32
#define MBEDTLS_BEFORE_COLON_STR "18"
int mbedtls_x509_crt_info(char *buf, size_t size, const char *prefix,
const mbedtls_x509_crt *crt)
Expand Down Expand Up @@ -1807,6 +1807,7 @@ int mbedtls_x509_crt_info(char *buf, size_t size, const char *prefix,
/* Key size */
if ((ret = mbedtls_x509_key_size_helper(key_size_str, MBEDTLS_BEFORE_COLON,
mbedtls_pk_get_name(&crt->pk))) != 0) {
assert(ret != MBEDTLS_ERR_X509_BUFFER_TOO_SMALL);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't use assert in the library.

Copy link
Author

@Mario-Klebsch Mario-Klebsch Oct 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The purpose of assert()ions is to signal errors in the internal logic of some software. In this case, supplying an insuffently sized buffer to mbedtls_x509_key_size_helper() in an error in the program logic. This is the reason, why I added an assertion.

Just remove it from my contribution, if you don't want to use this extra instrumentation in your code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like several libraries, we have a rule not to use assert(), but instead return an error and let the program decide what to do with it (termination may not be the best response).

Just remove it from my contribution, if you don't want to use this extra instrumentation in your code.

The way our review process works is that PR authors are supposed to make changes if needed. We don't normally merge patches that will need to be modified later.

return ret;
}

Expand Down
3 changes: 2 additions & 1 deletion library/x509_csr.c
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ int mbedtls_x509_csr_parse_file(mbedtls_x509_csr *csr, const char *path)
#endif /* MBEDTLS_FS_IO */

#if !defined(MBEDTLS_X509_REMOVE_INFO)
#define MBEDTLS_BEFORE_COLON 14
#define MBEDTLS_BEFORE_COLON 32
#define MBEDTLS_BEFORE_COLON_STR "14"
/*
* Return an informational string about the CSR.
Expand Down Expand Up @@ -552,6 +552,7 @@ int mbedtls_x509_csr_info(char *buf, size_t size, const char *prefix,

if ((ret = mbedtls_x509_key_size_helper(key_size_str, MBEDTLS_BEFORE_COLON,
mbedtls_pk_get_name(&csr->pk))) != 0) {
assert(ret != MBEDTLS_ERR_X509_BUFFER_TOO_SMALL);
return ret;
}

Expand Down