diff options
Diffstat (limited to 'src/lib/libcrypto/buffer/buffer.c')
| -rw-r--r-- | src/lib/libcrypto/buffer/buffer.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/lib/libcrypto/buffer/buffer.c b/src/lib/libcrypto/buffer/buffer.c index 620ea8d536..bc803ab6c8 100644 --- a/src/lib/libcrypto/buffer/buffer.c +++ b/src/lib/libcrypto/buffer/buffer.c | |||
| @@ -60,6 +60,11 @@ | |||
| 60 | #include "cryptlib.h" | 60 | #include "cryptlib.h" |
| 61 | #include <openssl/buffer.h> | 61 | #include <openssl/buffer.h> |
| 62 | 62 | ||
| 63 | /* LIMIT_BEFORE_EXPANSION is the maximum n such that (n+3)/3*4 < 2**31. That | ||
| 64 | * function is applied in several functions in this file and this limit ensures | ||
| 65 | * that the result fits in an int. */ | ||
| 66 | #define LIMIT_BEFORE_EXPANSION 0x5ffffffc | ||
| 67 | |||
| 63 | BUF_MEM *BUF_MEM_new(void) | 68 | BUF_MEM *BUF_MEM_new(void) |
| 64 | { | 69 | { |
| 65 | BUF_MEM *ret; | 70 | BUF_MEM *ret; |
| @@ -105,6 +110,12 @@ int BUF_MEM_grow(BUF_MEM *str, size_t len) | |||
| 105 | str->length=len; | 110 | str->length=len; |
| 106 | return(len); | 111 | return(len); |
| 107 | } | 112 | } |
| 113 | /* This limit is sufficient to ensure (len+3)/3*4 < 2**31 */ | ||
| 114 | if (len > LIMIT_BEFORE_EXPANSION) | ||
| 115 | { | ||
| 116 | BUFerr(BUF_F_BUF_MEM_GROW,ERR_R_MALLOC_FAILURE); | ||
| 117 | return 0; | ||
| 118 | } | ||
| 108 | n=(len+3)/3*4; | 119 | n=(len+3)/3*4; |
| 109 | if (str->data == NULL) | 120 | if (str->data == NULL) |
| 110 | ret=OPENSSL_malloc(n); | 121 | ret=OPENSSL_malloc(n); |
| @@ -142,6 +153,12 @@ int BUF_MEM_grow_clean(BUF_MEM *str, size_t len) | |||
| 142 | str->length=len; | 153 | str->length=len; |
| 143 | return(len); | 154 | return(len); |
| 144 | } | 155 | } |
| 156 | /* This limit is sufficient to ensure (len+3)/3*4 < 2**31 */ | ||
| 157 | if (len > LIMIT_BEFORE_EXPANSION) | ||
| 158 | { | ||
| 159 | BUFerr(BUF_F_BUF_MEM_GROW,ERR_R_MALLOC_FAILURE); | ||
| 160 | return 0; | ||
| 161 | } | ||
| 145 | n=(len+3)/3*4; | 162 | n=(len+3)/3*4; |
| 146 | if (str->data == NULL) | 163 | if (str->data == NULL) |
| 147 | ret=OPENSSL_malloc(n); | 164 | ret=OPENSSL_malloc(n); |
