Skip to content

Commit

Permalink
Fix integer overflow in evp_EncryptDecryptUpdate
Browse files Browse the repository at this point in the history
  • Loading branch information
hlandau committed Mar 11, 2022
1 parent d360208 commit 26e87d6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions crypto/evp/evp_enc.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ int EVP_DecryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
# define PTRDIFF_T size_t
#endif

int is_partially_overlapping(const void *ptr1, const void *ptr2, int len)
int is_partially_overlapping(const void *ptr1, const void *ptr2, size_t len)
{
PTRDIFF_T diff = (PTRDIFF_T)ptr1-(PTRDIFF_T)ptr2;
/*
Expand All @@ -299,7 +299,8 @@ static int evp_EncryptDecryptUpdate(EVP_CIPHER_CTX *ctx,
unsigned char *out, int *outl,
const unsigned char *in, int inl)
{
int i, j, bl, cmpl = inl;
int i, j, bl;
size_t cmpl = (size_t)inl;

if (EVP_CIPHER_CTX_test_flags(ctx, EVP_CIPH_FLAG_LENGTH_BITS))
cmpl = (cmpl + 7) / 8;
Expand Down Expand Up @@ -464,8 +465,9 @@ int EVP_EncryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
const unsigned char *in, int inl)
{
int fix_len, cmpl = inl;
int fix_len;
unsigned int b;
size_t cmpl = (size_t)inl;

/* Prevent accidental use of encryption context when decrypting */
if (ctx->encrypt) {
Expand Down
2 changes: 1 addition & 1 deletion crypto/evp/evp_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ struct evp_Encode_Ctx_st {
typedef struct evp_pbe_st EVP_PBE_CTL;
DEFINE_STACK_OF(EVP_PBE_CTL)

int is_partially_overlapping(const void *ptr1, const void *ptr2, int len);
int is_partially_overlapping(const void *ptr1, const void *ptr2, size_t len);

0 comments on commit 26e87d6

Please sign in to comment.