diff options
Diffstat (limited to 'src/lib/libcrypto/evp/bio_b64.c')
| -rw-r--r-- | src/lib/libcrypto/evp/bio_b64.c | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/src/lib/libcrypto/evp/bio_b64.c b/src/lib/libcrypto/evp/bio_b64.c index 6e550f6a43..33349c2f98 100644 --- a/src/lib/libcrypto/evp/bio_b64.c +++ b/src/lib/libcrypto/evp/bio_b64.c | |||
| @@ -184,7 +184,9 @@ static int b64_read(BIO *b, char *out, int outl) | |||
| 184 | ret_code=0; | 184 | ret_code=0; |
| 185 | while (outl > 0) | 185 | while (outl > 0) |
| 186 | { | 186 | { |
| 187 | if (ctx->cont <= 0) break; | 187 | |
| 188 | if (ctx->cont <= 0) | ||
| 189 | break; | ||
| 188 | 190 | ||
| 189 | i=BIO_read(b->next_bio,&(ctx->tmp[ctx->tmp_len]), | 191 | i=BIO_read(b->next_bio,&(ctx->tmp[ctx->tmp_len]), |
| 190 | B64_BLOCK_SIZE-ctx->tmp_len); | 192 | B64_BLOCK_SIZE-ctx->tmp_len); |
| @@ -195,11 +197,21 @@ static int b64_read(BIO *b, char *out, int outl) | |||
| 195 | 197 | ||
| 196 | /* Should be continue next time we are called? */ | 198 | /* Should be continue next time we are called? */ |
| 197 | if (!BIO_should_retry(b->next_bio)) | 199 | if (!BIO_should_retry(b->next_bio)) |
| 200 | { | ||
| 198 | ctx->cont=i; | 201 | ctx->cont=i; |
| 199 | /* else we should continue when called again */ | 202 | /* If buffer empty break */ |
| 200 | break; | 203 | if(ctx->tmp_len == 0) |
| 204 | break; | ||
| 205 | /* Fall through and process what we have */ | ||
| 206 | else | ||
| 207 | i = 0; | ||
| 208 | } | ||
| 209 | /* else we retry and add more data to buffer */ | ||
| 210 | else | ||
| 211 | break; | ||
| 201 | } | 212 | } |
| 202 | i+=ctx->tmp_len; | 213 | i+=ctx->tmp_len; |
| 214 | ctx->tmp_len = i; | ||
| 203 | 215 | ||
| 204 | /* We need to scan, a line at a time until we | 216 | /* We need to scan, a line at a time until we |
| 205 | * have a valid line if we are starting. */ | 217 | * have a valid line if we are starting. */ |
| @@ -255,8 +267,12 @@ static int b64_read(BIO *b, char *out, int outl) | |||
| 255 | * reading until a new line. */ | 267 | * reading until a new line. */ |
| 256 | if (p == (unsigned char *)&(ctx->tmp[0])) | 268 | if (p == (unsigned char *)&(ctx->tmp[0])) |
| 257 | { | 269 | { |
| 258 | ctx->tmp_nl=1; | 270 | /* Check buffer full */ |
| 259 | ctx->tmp_len=0; | 271 | if (i == B64_BLOCK_SIZE) |
| 272 | { | ||
| 273 | ctx->tmp_nl=1; | ||
| 274 | ctx->tmp_len=0; | ||
| 275 | } | ||
| 260 | } | 276 | } |
| 261 | else if (p != q) /* finished on a '\n' */ | 277 | else if (p != q) /* finished on a '\n' */ |
| 262 | { | 278 | { |
| @@ -271,6 +287,11 @@ static int b64_read(BIO *b, char *out, int outl) | |||
| 271 | else | 287 | else |
| 272 | ctx->tmp_len=0; | 288 | ctx->tmp_len=0; |
| 273 | } | 289 | } |
| 290 | /* If buffer isn't full and we can retry then | ||
| 291 | * restart to read in more data. | ||
| 292 | */ | ||
| 293 | else if ((i < B64_BLOCK_SIZE) && (ctx->cont > 0)) | ||
| 294 | continue; | ||
| 274 | 295 | ||
| 275 | if (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL) | 296 | if (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL) |
| 276 | { | 297 | { |
| @@ -310,8 +331,8 @@ static int b64_read(BIO *b, char *out, int outl) | |||
| 310 | i=EVP_DecodeUpdate(&(ctx->base64), | 331 | i=EVP_DecodeUpdate(&(ctx->base64), |
| 311 | (unsigned char *)ctx->buf,&ctx->buf_len, | 332 | (unsigned char *)ctx->buf,&ctx->buf_len, |
| 312 | (unsigned char *)ctx->tmp,i); | 333 | (unsigned char *)ctx->tmp,i); |
| 334 | ctx->tmp_len = 0; | ||
| 313 | } | 335 | } |
| 314 | ctx->cont=i; | ||
| 315 | ctx->buf_off=0; | 336 | ctx->buf_off=0; |
| 316 | if (i < 0) | 337 | if (i < 0) |
| 317 | { | 338 | { |
| @@ -484,10 +505,7 @@ again: | |||
| 484 | { | 505 | { |
| 485 | i=b64_write(b,NULL,0); | 506 | i=b64_write(b,NULL,0); |
| 486 | if (i < 0) | 507 | if (i < 0) |
| 487 | { | 508 | return i; |
| 488 | ret=i; | ||
| 489 | break; | ||
| 490 | } | ||
| 491 | } | 509 | } |
| 492 | if (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL) | 510 | if (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL) |
| 493 | { | 511 | { |
