You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-23 15:16:17 +00:00
mbedtls: Update to upstream version 2.28.2
(cherry picked from commit 6e65244b6b)
This commit is contained in:
52
thirdparty/mbedtls/library/x509.c
vendored
52
thirdparty/mbedtls/library/x509.c
vendored
@@ -43,16 +43,7 @@
|
||||
#include "mbedtls/pem.h"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#define mbedtls_free free
|
||||
#define mbedtls_calloc calloc
|
||||
#define mbedtls_printf printf
|
||||
#define mbedtls_snprintf snprintf
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_HAVE_TIME)
|
||||
#include "mbedtls/platform_time.h"
|
||||
@@ -198,7 +189,7 @@ static int x509_get_hash_alg( const mbedtls_x509_buf *alg, mbedtls_md_type_t *md
|
||||
*
|
||||
* RFC 4055 (which defines use of RSASSA-PSS in PKIX) states that the value
|
||||
* of trailerField MUST be 1, and PKCS#1 v2.2 doesn't even define any other
|
||||
* option. Enfore this at parsing time.
|
||||
* option. Enforce this at parsing time.
|
||||
*/
|
||||
int mbedtls_x509_get_rsassa_pss_params( const mbedtls_x509_buf *params,
|
||||
mbedtls_md_type_t *md_alg, mbedtls_md_type_t *mgf_md,
|
||||
@@ -424,6 +415,11 @@ static int x509_get_attr_type_value( unsigned char **p,
|
||||
* For the general case we still use a flat list, but we mark elements of the
|
||||
* same set so that they are "merged" together in the functions that consume
|
||||
* this list, eg mbedtls_x509_dn_gets().
|
||||
*
|
||||
* On success, this function may allocate a linked list starting at cur->next
|
||||
* that must later be free'd by the caller using mbedtls_free(). In error
|
||||
* cases, this function frees all allocated memory internally and the caller
|
||||
* has no freeing responsibilities.
|
||||
*/
|
||||
int mbedtls_x509_get_name( unsigned char **p, const unsigned char *end,
|
||||
mbedtls_x509_name *cur )
|
||||
@@ -431,6 +427,8 @@ int mbedtls_x509_get_name( unsigned char **p, const unsigned char *end,
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
size_t set_len;
|
||||
const unsigned char *end_set;
|
||||
mbedtls_x509_name *head = cur;
|
||||
mbedtls_x509_name *prev, *allocated;
|
||||
|
||||
/* don't use recursion, we'd risk stack overflow if not optimized */
|
||||
while( 1 )
|
||||
@@ -440,14 +438,17 @@ int mbedtls_x509_get_name( unsigned char **p, const unsigned char *end,
|
||||
*/
|
||||
if( ( ret = mbedtls_asn1_get_tag( p, end, &set_len,
|
||||
MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SET ) ) != 0 )
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_NAME, ret ) );
|
||||
{
|
||||
ret = MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_NAME, ret );
|
||||
goto error;
|
||||
}
|
||||
|
||||
end_set = *p + set_len;
|
||||
|
||||
while( 1 )
|
||||
{
|
||||
if( ( ret = x509_get_attr_type_value( p, end_set, cur ) ) != 0 )
|
||||
return( ret );
|
||||
goto error;
|
||||
|
||||
if( *p == end_set )
|
||||
break;
|
||||
@@ -458,7 +459,10 @@ int mbedtls_x509_get_name( unsigned char **p, const unsigned char *end,
|
||||
cur->next = mbedtls_calloc( 1, sizeof( mbedtls_x509_name ) );
|
||||
|
||||
if( cur->next == NULL )
|
||||
return( MBEDTLS_ERR_X509_ALLOC_FAILED );
|
||||
{
|
||||
ret = MBEDTLS_ERR_X509_ALLOC_FAILED;
|
||||
goto error;
|
||||
}
|
||||
|
||||
cur = cur->next;
|
||||
}
|
||||
@@ -472,10 +476,30 @@ int mbedtls_x509_get_name( unsigned char **p, const unsigned char *end,
|
||||
cur->next = mbedtls_calloc( 1, sizeof( mbedtls_x509_name ) );
|
||||
|
||||
if( cur->next == NULL )
|
||||
return( MBEDTLS_ERR_X509_ALLOC_FAILED );
|
||||
{
|
||||
ret = MBEDTLS_ERR_X509_ALLOC_FAILED;
|
||||
goto error;
|
||||
}
|
||||
|
||||
cur = cur->next;
|
||||
}
|
||||
|
||||
error:
|
||||
/* Skip the first element as we did not allocate it */
|
||||
allocated = head->next;
|
||||
|
||||
while( allocated != NULL )
|
||||
{
|
||||
prev = allocated;
|
||||
allocated = allocated->next;
|
||||
|
||||
mbedtls_platform_zeroize( prev, sizeof( *prev ) );
|
||||
mbedtls_free( prev );
|
||||
}
|
||||
|
||||
mbedtls_platform_zeroize( head, sizeof( *head ) );
|
||||
|
||||
return( ret );
|
||||
}
|
||||
|
||||
static int x509_parse_int( unsigned char **p, size_t n, int *res )
|
||||
|
||||
Reference in New Issue
Block a user