From 47f1d7be950d44bc2fb404f9e3530aee7d2ae757 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Wed, 7 May 2025 21:04:51 +0200 Subject: [PATCH] Replace MBEDTLS_ERR_OID_BUF_TOO_SMALL with PSA_ERROR_BUFFER_TOO_SMALL Remove the definition of `MBEDTLS_ERR_OID_BUF_TOO_SMALL` in `x509_oid.h`, and use the corresponding PSA error instead. ``` git grep -l MBEDTLS_ERR_OID_BUF_TOO_SMALL | xargs perl -i -pe 's/\bMBEDTLS_ERR_OID_BUF_TOO_SMALL\b/PSA_ERROR_BUFFER_TOO_SMALL/p' edit library/x509_oid.h ``` Signed-off-by: Gilles Peskine --- include/mbedtls/x509.h | 2 +- library/x509.c | 4 ++-- library/x509_create.c | 2 +- library/x509_oid.h | 2 -- tests/suites/test_suite_x509parse.data | 2 +- 5 files changed, 5 insertions(+), 7 deletions(-) diff --git a/include/mbedtls/x509.h b/include/mbedtls/x509.h index 9d988a1a97..5a3bd8a2a1 100644 --- a/include/mbedtls/x509.h +++ b/include/mbedtls/x509.h @@ -498,7 +498,7 @@ size_t mbedtls_x509_crt_parse_cn_inet_pton(const char *cn, void *dst); * \param oid OID to translate * * \return Length of the string written (excluding final NULL) or - * MBEDTLS_ERR_OID_BUF_TOO_SMALL in case of error + * PSA_ERROR_BUFFER_TOO_SMALL in case of error */ int mbedtls_oid_get_numeric_string(char *buf, size_t size, const mbedtls_asn1_buf *oid); diff --git a/library/x509.c b/library/x509.c index a3d7a18b1c..fe4e3e3afe 100644 --- a/library/x509.c +++ b/library/x509.c @@ -849,7 +849,7 @@ int mbedtls_oid_get_numeric_string(char *buf, size_t size, ret = mbedtls_snprintf(p, n, ".%u", value); } if (ret < 2 || (size_t) ret >= n) { - return MBEDTLS_ERR_OID_BUF_TOO_SMALL; + return PSA_ERROR_BUFFER_TOO_SMALL; } n -= (size_t) ret; p += ret; @@ -912,7 +912,7 @@ int mbedtls_x509_dn_gets(char *buf, size_t size, const mbedtls_x509_name *dn) p += ret; ret = mbedtls_snprintf(p, n, "="); print_hexstring = 1; - } else if (ret == MBEDTLS_ERR_OID_BUF_TOO_SMALL) { + } else if (ret == PSA_ERROR_BUFFER_TOO_SMALL) { return MBEDTLS_ERR_X509_BUFFER_TOO_SMALL; } else { ret = mbedtls_snprintf(p, n, "\?\?="); diff --git a/library/x509_create.c b/library/x509_create.c index 7ca5517528..7621698d5a 100644 --- a/library/x509_create.c +++ b/library/x509_create.c @@ -314,7 +314,7 @@ static int oid_subidentifier_encode_into(unsigned char **p, size_t num_bytes = oid_subidentifier_num_bytes(value); if ((size_t) (bound - *p) < num_bytes) { - return MBEDTLS_ERR_OID_BUF_TOO_SMALL; + return PSA_ERROR_BUFFER_TOO_SMALL; } (*p)[num_bytes - 1] = (unsigned char) (value & 0x7f); value >>= 7; diff --git a/library/x509_oid.h b/library/x509_oid.h index 5b12677a61..46cfd54adc 100644 --- a/library/x509_oid.h +++ b/library/x509_oid.h @@ -21,8 +21,6 @@ /** OID is not found. */ #define MBEDTLS_ERR_OID_NOT_FOUND -0x002E -/** output buffer is too small */ -#define MBEDTLS_ERR_OID_BUF_TOO_SMALL -0x000B /* * Maximum number of OID components allowed diff --git a/tests/suites/test_suite_x509parse.data b/tests/suites/test_suite_x509parse.data index bbdd9f90db..6a04ff0f5e 100644 --- a/tests/suites/test_suite_x509parse.data +++ b/tests/suites/test_suite_x509parse.data @@ -2737,7 +2737,7 @@ X509 OID numstring #2 (buffer just fits) x509_oid_numstr:"2b06010505070301":"1.3.6.1.5.5.7.3.1":18:17 X509 OID numstring #3 (buffer too small) -x509_oid_numstr:"2b06010505070301":"1.3.6.1.5.5.7.3.1":17:MBEDTLS_ERR_OID_BUF_TOO_SMALL +x509_oid_numstr:"2b06010505070301":"1.3.6.1.5.5.7.3.1":17:PSA_ERROR_BUFFER_TOO_SMALL X509 OID numstring #4 (larger number) x509_oid_numstr:"2a864886f70d":"1.2.840.113549":15:14