X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=crypto%2Fevp%2Fbio_b64.c;h=f12eac1b55a06b37a49d1d579f1b65d7edb9fca0;hb=c938563a81d48e1d23bddcf9283d4961794db132;hp=a275ef4c7d0a1923b0ca6fe08651ccde6ec43473;hpb=26a3a48d65c7464b400ec1de439994d7f0d25fed;p=oweals%2Fopenssl.git diff --git a/crypto/evp/bio_b64.c b/crypto/evp/bio_b64.c index a275ef4c7d..f12eac1b55 100644 --- a/crypto/evp/bio_b64.c +++ b/crypto/evp/bio_b64.c @@ -69,7 +69,7 @@ static int b64_read(BIO *h, char *buf, int size); static long b64_ctrl(BIO *h, int cmd, long arg1, void *arg2); static int b64_new(BIO *h); static int b64_free(BIO *data); -static long b64_callback_ctrl(BIO *h,int cmd,void (*fp)()); +static long b64_callback_ctrl(BIO *h,int cmd,bio_info_cb *fp); #define B64_BLOCK_SIZE 1024 #define B64_BLOCK_SIZE2 768 #define B64_NONE 0 @@ -370,10 +370,11 @@ static int b64_write(BIO *b, const char *in, int inl) n-=i; } /* at this point all pending data has been written */ + ctx->buf_off=0; + ctx->buf_len=0; if ((in == NULL) || (inl <= 0)) return(0); - ctx->buf_off=0; while (inl > 0) { n=(inl > B64_BLOCK_SIZE)?B64_BLOCK_SIZE:inl; @@ -383,14 +384,20 @@ static int b64_write(BIO *b, const char *in, int inl) if (ctx->tmp_len > 0) { n=3-ctx->tmp_len; + /* There's a teoretical possibility for this */ + if (n > inl) + n=inl; memcpy(&(ctx->tmp[ctx->tmp_len]),in,n); ctx->tmp_len+=n; - n=ctx->tmp_len; - if (n < 3) + if (ctx->tmp_len < 3) break; ctx->buf_len=EVP_EncodeBlock( (unsigned char *)ctx->buf, - (unsigned char *)ctx->tmp,n); + (unsigned char *)ctx->tmp, + ctx->tmp_len); + /* Since we're now done using the temporary + buffer, the length should be 0'd */ + ctx->tmp_len=0; } else { @@ -458,7 +465,8 @@ static long b64_ctrl(BIO *b, int cmd, long num, void *ptr) break; case BIO_CTRL_WPENDING: /* More to write in buffer */ ret=ctx->buf_len-ctx->buf_off; - if ((ret == 0) && (ctx->base64.num != 0)) + if ((ret == 0) && (ctx->encode != B64_NONE) + && (ctx->base64.num != 0)) ret=1; else if (ret <= 0) ret=BIO_ctrl(b->next_bio,cmd,num,ptr); @@ -493,7 +501,7 @@ again: goto again; } } - else if (ctx->base64.num != 0) + else if (ctx->encode != B64_NONE && ctx->base64.num != 0) { ctx->buf_off=0; EVP_EncodeFinal(&(ctx->base64), @@ -524,7 +532,7 @@ again: return(ret); } -static long b64_callback_ctrl(BIO *b, int cmd, void (*fp)()) +static long b64_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) { long ret=1;