summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/evp/bio_b64.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/evp/bio_b64.c')
-rw-r--r--src/lib/libcrypto/evp/bio_b64.c37
1 files changed, 22 insertions, 15 deletions
diff --git a/src/lib/libcrypto/evp/bio_b64.c b/src/lib/libcrypto/evp/bio_b64.c
index bd5e24f993..af6fa2ae8f 100644
--- a/src/lib/libcrypto/evp/bio_b64.c
+++ b/src/lib/libcrypto/evp/bio_b64.c
@@ -62,14 +62,14 @@
62#include <openssl/buffer.h> 62#include <openssl/buffer.h>
63#include <openssl/evp.h> 63#include <openssl/evp.h>
64 64
65static int b64_write(BIO *h,char *buf,int num); 65static int b64_write(BIO *h, const char *buf, int num);
66static int b64_read(BIO *h,char *buf,int size); 66static int b64_read(BIO *h, char *buf, int size);
67/*static int b64_puts(BIO *h,char *str); */ 67/*static int b64_puts(BIO *h, const char *str); */
68/*static int b64_gets(BIO *h,char *str,int size); */ 68/*static int b64_gets(BIO *h, char *str, int size); */
69static long b64_ctrl(BIO *h,int cmd,long arg1,char *arg2); 69static long b64_ctrl(BIO *h, int cmd, long arg1, void *arg2);
70static int b64_new(BIO *h); 70static int b64_new(BIO *h);
71static int b64_free(BIO *data); 71static int b64_free(BIO *data);
72static long b64_callback_ctrl(BIO *h,int cmd,void (*fp)()); 72static long b64_callback_ctrl(BIO *h,int cmd,bio_info_cb *fp);
73#define B64_BLOCK_SIZE 1024 73#define B64_BLOCK_SIZE 1024
74#define B64_BLOCK_SIZE2 768 74#define B64_BLOCK_SIZE2 768
75#define B64_NONE 0 75#define B64_NONE 0
@@ -113,7 +113,7 @@ static int b64_new(BIO *bi)
113 { 113 {
114 BIO_B64_CTX *ctx; 114 BIO_B64_CTX *ctx;
115 115
116 ctx=(BIO_B64_CTX *)Malloc(sizeof(BIO_B64_CTX)); 116 ctx=(BIO_B64_CTX *)OPENSSL_malloc(sizeof(BIO_B64_CTX));
117 if (ctx == NULL) return(0); 117 if (ctx == NULL) return(0);
118 118
119 ctx->buf_len=0; 119 ctx->buf_len=0;
@@ -133,7 +133,7 @@ static int b64_new(BIO *bi)
133static int b64_free(BIO *a) 133static int b64_free(BIO *a)
134 { 134 {
135 if (a == NULL) return(0); 135 if (a == NULL) return(0);
136 Free(a->ptr); 136 OPENSSL_free(a->ptr);
137 a->ptr=NULL; 137 a->ptr=NULL;
138 a->init=0; 138 a->init=0;
139 a->flags=0; 139 a->flags=0;
@@ -340,7 +340,7 @@ static int b64_read(BIO *b, char *out, int outl)
340 return((ret == 0)?ret_code:ret); 340 return((ret == 0)?ret_code:ret);
341 } 341 }
342 342
343static int b64_write(BIO *b, char *in, int inl) 343static int b64_write(BIO *b, const char *in, int inl)
344 { 344 {
345 int ret=inl,n,i; 345 int ret=inl,n,i;
346 BIO_B64_CTX *ctx; 346 BIO_B64_CTX *ctx;
@@ -370,10 +370,11 @@ static int b64_write(BIO *b, char *in, int inl)
370 n-=i; 370 n-=i;
371 } 371 }
372 /* at this point all pending data has been written */ 372 /* at this point all pending data has been written */
373 ctx->buf_off=0;
374 ctx->buf_len=0;
373 375
374 if ((in == NULL) || (inl <= 0)) return(0); 376 if ((in == NULL) || (inl <= 0)) return(0);
375 377
376 ctx->buf_off=0;
377 while (inl > 0) 378 while (inl > 0)
378 { 379 {
379 n=(inl > B64_BLOCK_SIZE)?B64_BLOCK_SIZE:inl; 380 n=(inl > B64_BLOCK_SIZE)?B64_BLOCK_SIZE:inl;
@@ -383,14 +384,20 @@ static int b64_write(BIO *b, char *in, int inl)
383 if (ctx->tmp_len > 0) 384 if (ctx->tmp_len > 0)
384 { 385 {
385 n=3-ctx->tmp_len; 386 n=3-ctx->tmp_len;
387 /* There's a teoretical possibility for this */
388 if (n > inl)
389 n=inl;
386 memcpy(&(ctx->tmp[ctx->tmp_len]),in,n); 390 memcpy(&(ctx->tmp[ctx->tmp_len]),in,n);
387 ctx->tmp_len+=n; 391 ctx->tmp_len+=n;
388 n=ctx->tmp_len; 392 if (ctx->tmp_len < 3)
389 if (n < 3)
390 break; 393 break;
391 ctx->buf_len=EVP_EncodeBlock( 394 ctx->buf_len=EVP_EncodeBlock(
392 (unsigned char *)ctx->buf, 395 (unsigned char *)ctx->buf,
393 (unsigned char *)ctx->tmp,n); 396 (unsigned char *)ctx->tmp,
397 ctx->tmp_len);
398 /* Since we're now done using the temporary
399 buffer, the length should be 0'd */
400 ctx->tmp_len=0;
394 } 401 }
395 else 402 else
396 { 403 {
@@ -434,7 +441,7 @@ static int b64_write(BIO *b, char *in, int inl)
434 return(ret); 441 return(ret);
435 } 442 }
436 443
437static long b64_ctrl(BIO *b, int cmd, long num, char *ptr) 444static long b64_ctrl(BIO *b, int cmd, long num, void *ptr)
438 { 445 {
439 BIO_B64_CTX *ctx; 446 BIO_B64_CTX *ctx;
440 long ret=1; 447 long ret=1;
@@ -524,7 +531,7 @@ again:
524 return(ret); 531 return(ret);
525 } 532 }
526 533
527static long b64_callback_ctrl(BIO *b, int cmd, void (*fp)()) 534static long b64_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
528 { 535 {
529 long ret=1; 536 long ret=1;
530 537