提交 2bd5d70c 编写于 作者: M Matt Caswell

Ensure EVP_EncodeUpdate handles an output length that is too long

With the EVP_EncodeUpdate function it is the caller's responsibility to
determine how big the output buffer should be. The function writes the
amount actually used to |*outl|. However this could go negative with a
sufficiently large value for |inl|. We add a check for this error
condition.
Reviewed-by: NRichard Levitte <levitte@openssl.org>
上级 ee1e3cac
...@@ -56,6 +56,7 @@ ...@@ -56,6 +56,7 @@
*/ */
#include <stdio.h> #include <stdio.h>
#include <limits.h>
#include "internal/cryptlib.h" #include "internal/cryptlib.h"
#include <openssl/evp.h> #include <openssl/evp.h>
#include "evp_locl.h" #include "evp_locl.h"
...@@ -165,7 +166,7 @@ void EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl, ...@@ -165,7 +166,7 @@ void EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl,
const unsigned char *in, int inl) const unsigned char *in, int inl)
{ {
int i, j; int i, j;
unsigned int total = 0; size_t total = 0;
*outl = 0; *outl = 0;
if (inl <= 0) if (inl <= 0)
...@@ -188,7 +189,7 @@ void EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl, ...@@ -188,7 +189,7 @@ void EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl,
*out = '\0'; *out = '\0';
total = j + 1; total = j + 1;
} }
while (inl >= ctx->length) { while (inl >= ctx->length && total <= INT_MAX) {
j = EVP_EncodeBlock(out, in, ctx->length); j = EVP_EncodeBlock(out, in, ctx->length);
in += ctx->length; in += ctx->length;
inl -= ctx->length; inl -= ctx->length;
...@@ -197,6 +198,11 @@ void EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl, ...@@ -197,6 +198,11 @@ void EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl,
*out = '\0'; *out = '\0';
total += j + 1; total += j + 1;
} }
if (total > INT_MAX) {
/* Too much output data! */
*outl = 0;
return;
}
if (inl != 0) if (inl != 0)
memcpy(&(ctx->enc_data[0]), in, inl); memcpy(&(ctx->enc_data[0]), in, inl);
ctx->num = inl; ctx->num = inl;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册