Add EVP_EncodedLength. Several callers of EVP_EncodeBlock are doing ad-hoc versions of this function without any overflow checks. Change-Id: I4d0cad2347ea8c44b42465e8b14b2783db69ee8f Reviewed-on: https://boringssl-review.googlesource.com/1511 Reviewed-by: David Benjamin <davidben@chromium.org> Reviewed-by: Adam Langley <agl@google.com>
diff --git a/include/openssl/base64.h b/include/openssl/base64.h index 38cb0ee..521004a 100644 --- a/include/openssl/base64.h +++ b/include/openssl/base64.h
@@ -102,6 +102,12 @@ OPENSSL_EXPORT size_t EVP_EncodeBlock(uint8_t *dst, const uint8_t *src, size_t src_len); +/* EVP_EncodedLength sets |*out_len| to the number of bytes that will be needed + * to call |EVP_EncodeBlock| on an input of length |len|. This includes the + * final NUL that |EVP_EncodeBlock| writes. It returns one on success or zero + * on error. */ +int EVP_EncodedLength(size_t *out_len, size_t len); + /* Decoding */
diff --git a/include/openssl/err.h b/include/openssl/err.h index 8ebd73f..d8e7cd5 100644 --- a/include/openssl/err.h +++ b/include/openssl/err.h
@@ -444,6 +444,7 @@ #define ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED (2 | ERR_R_FATAL) #define ERR_R_PASSED_NULL_PARAMETER (3 | ERR_R_FATAL) #define ERR_R_INTERNAL_ERROR (4 | ERR_R_FATAL) +#define ERR_R_OVERFLOW (5 | ERR_R_FATAL) /* System error functions */ #define SYS_F_fopen 100