diff --git a/include/mbedtls/oid.h b/include/mbedtls/oid.h index da3d70ed5..68ae72317 100644 --- a/include/mbedtls/oid.h +++ b/include/mbedtls/oid.h @@ -479,8 +479,9 @@ int mbedtls_oid_get_numeric_string(char *buf, size_t size, const mbedtls_asn1_bu * heap. It must be freed by the caller using mbedtls_free(). * * \param oid #mbedtls_asn1_buf to populate with the DER-encoded OID - * \param oid_str string representation of the OID to parse - * \param size length of the OID string + * \param oid_str string representation of the OID to parse, not + * NUL-terminated + * \param size length of the OID string, not including any NUL terminator * * \return 0 if successful * \return #MBEDTLS_ERR_ASN1_INVALID_DATA if \p oid_str does not diff --git a/library/oid.c b/library/oid.c index 87e5d892f..312a6375b 100644 --- a/library/oid.c +++ b/library/oid.c @@ -960,7 +960,7 @@ int mbedtls_oid_from_numeric_string(mbedtls_asn1_buf *oid, size_t encoded_len; unsigned char *minimum_mem; - for (size_t i = 0; (i < size) && (oid_str[i] != '\0'); i++) { + for (size_t i = 0; i < size; i++) { if (oid_str[i] == '.') { num_dots++; } @@ -1003,7 +1003,7 @@ int mbedtls_oid_from_numeric_string(mbedtls_asn1_buf *oid, ret = MBEDTLS_ERR_ASN1_INVALID_DATA; goto error; } - if (str_ptr < str_bound && *str_ptr != '\0') { + if (str_ptr < str_bound) { if (*str_ptr == '.') { str_ptr++; } else { @@ -1022,12 +1022,12 @@ int mbedtls_oid_from_numeric_string(mbedtls_asn1_buf *oid, goto error; } - while (str_ptr < str_bound && *str_ptr != '\0') { + while (str_ptr < str_bound) { ret = oid_parse_number(&val, &str_ptr, str_bound); if (ret != 0) { goto error; } - if (str_ptr < str_bound && *str_ptr != '\0') { + if (str_ptr < str_bound) { if (*str_ptr == '.') { str_ptr++; } else {