Use a block to save 12b

Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
This commit is contained in:
Dave Rodgman 2023-10-12 16:55:23 +01:00
parent 351a81c65d
commit 584c8108b3

View file

@ -218,8 +218,6 @@ static int parse_attribute_value_hex_der_encoded(const char *s,
size_t *data_len, size_t *data_len,
int *tag) int *tag)
{ {
unsigned char *p;
/* Step 1: preliminary length checks. */ /* Step 1: preliminary length checks. */
/* Each byte is encoded by exactly two hexadecimal digits. */ /* Each byte is encoded by exactly two hexadecimal digits. */
if (len % 2 != 0) { if (len % 2 != 0) {
@ -256,31 +254,33 @@ static int parse_attribute_value_hex_der_encoded(const char *s,
/* Step 3: decode the DER. */ /* Step 3: decode the DER. */
/* We've checked that der_length >= 1 above. */ /* We've checked that der_length >= 1 above. */
*tag = der[0]; *tag = der[0];
p = der + 1; {
if (mbedtls_asn1_get_len(&p, der + der_length, data_len) != 0) { unsigned char *p = der + 1;
goto error; if (mbedtls_asn1_get_len(&p, der + der_length, data_len) != 0) {
} goto error;
/* Now p points to the first byte of the payload inside der, }
* and *data_len is the length of the payload. */ /* Now p points to the first byte of the payload inside der,
* and *data_len is the length of the payload. */
/* Step 4: payload validation */ /* Step 4: payload validation */
if (*data_len > MBEDTLS_X509_MAX_DN_NAME_SIZE) { if (*data_len > MBEDTLS_X509_MAX_DN_NAME_SIZE) {
goto error; goto error;
} }
/* Strings must not contain null bytes. */ /* Strings must not contain null bytes. */
if (MBEDTLS_ASN1_IS_STRING_TAG(*tag)) { if (MBEDTLS_ASN1_IS_STRING_TAG(*tag)) {
for (size_t i = 0; i < *data_len; i++) { for (size_t i = 0; i < *data_len; i++) {
if (p[i] == 0) { if (p[i] == 0) {
goto error; goto error;
}
} }
} }
}
/* Step 5: output the payload. */ /* Step 5: output the payload. */
if (*data_len > data_size) { if (*data_len > data_size) {
goto error; goto error;
}
memcpy(data, p, *data_len);
} }
memcpy(data, p, *data_len);
mbedtls_free(der); mbedtls_free(der);
return 0; return 0;