X-Git-Url: https://git.openssl.org/gitweb/?p=openssl.git;a=blobdiff_plain;f=crypto%2Fbio%2Fbf_buff.c;h=c65dc142a5c3af239d4c8dbe145c95212679f1a3;hp=d239fc000853bf7fad615227f64ef49a8af38488;hb=130832150c1313824868b154cccda3ace88fa950;hpb=ec577822f95a8bca0023c5c77cef1a4916822d4a diff --git a/crypto/bio/bf_buff.c b/crypto/bio/bf_buff.c index d239fc0008..c65dc142a5 100644 --- a/crypto/bio/bf_buff.c +++ b/crypto/bio/bf_buff.c @@ -62,24 +62,14 @@ #include #include -#ifndef NOPROTO -static int buffer_write(BIO *h,char *buf,int num); -static int buffer_read(BIO *h,char *buf,int size); -static int buffer_puts(BIO *h,char *str); -static int buffer_gets(BIO *h,char *str,int size); -static long buffer_ctrl(BIO *h,int cmd,long arg1,char *arg2); +static int buffer_write(BIO *h, const char *buf,int num); +static int buffer_read(BIO *h, char *buf, int size); +static int buffer_puts(BIO *h, const char *str); +static int buffer_gets(BIO *h, char *str, int size); +static long buffer_ctrl(BIO *h, int cmd, long arg1, void *arg2); static int buffer_new(BIO *h); static int buffer_free(BIO *data); -#else -static int buffer_write(); -static int buffer_read(); -static int buffer_puts(); -static int buffer_gets(); -static long buffer_ctrl(); -static int buffer_new(); -static int buffer_free(); -#endif - +static long buffer_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp); #define DEFAULT_BUFFER_SIZE 1024 static BIO_METHOD methods_buffer= @@ -93,6 +83,7 @@ static BIO_METHOD methods_buffer= buffer_ctrl, buffer_new, buffer_free, + buffer_callback_ctrl, }; BIO_METHOD *BIO_f_buffer(void) @@ -104,12 +95,12 @@ static int buffer_new(BIO *bi) { BIO_F_BUFFER_CTX *ctx; - ctx=(BIO_F_BUFFER_CTX *)Malloc(sizeof(BIO_F_BUFFER_CTX)); + ctx=(BIO_F_BUFFER_CTX *)OPENSSL_malloc(sizeof(BIO_F_BUFFER_CTX)); if (ctx == NULL) return(0); - ctx->ibuf=(char *)Malloc(DEFAULT_BUFFER_SIZE); - if (ctx->ibuf == NULL) { Free(ctx); return(0); } - ctx->obuf=(char *)Malloc(DEFAULT_BUFFER_SIZE); - if (ctx->obuf == NULL) { Free(ctx->ibuf); Free(ctx); return(0); } + ctx->ibuf=(char *)OPENSSL_malloc(DEFAULT_BUFFER_SIZE); + if (ctx->ibuf == NULL) { OPENSSL_free(ctx); return(0); } + ctx->obuf=(char *)OPENSSL_malloc(DEFAULT_BUFFER_SIZE); + if (ctx->obuf == NULL) { OPENSSL_free(ctx->ibuf); OPENSSL_free(ctx); return(0); } ctx->ibuf_size=DEFAULT_BUFFER_SIZE; ctx->obuf_size=DEFAULT_BUFFER_SIZE; ctx->ibuf_len=0; @@ -129,9 +120,9 @@ static int buffer_free(BIO *a) if (a == NULL) return(0); b=(BIO_F_BUFFER_CTX *)a->ptr; - if (b->ibuf != NULL) Free(b->ibuf); - if (b->obuf != NULL) Free(b->obuf); - Free(a->ptr); + if (b->ibuf != NULL) OPENSSL_free(b->ibuf); + if (b->obuf != NULL) OPENSSL_free(b->obuf); + OPENSSL_free(a->ptr); a->ptr=NULL; a->init=0; a->flags=0; @@ -204,7 +195,7 @@ start: goto start; } -static int buffer_write(BIO *b, char *in, int inl) +static int buffer_write(BIO *b, const char *in, int inl) { int i,num=0; BIO_F_BUFFER_CTX *ctx; @@ -277,7 +268,7 @@ start: goto start; } -static long buffer_ctrl(BIO *b, int cmd, long num, char *ptr) +static long buffer_ctrl(BIO *b, int cmd, long num, void *ptr) { BIO *dbio; BIO_F_BUFFER_CTX *ctx; @@ -295,6 +286,7 @@ static long buffer_ctrl(BIO *b, int cmd, long num, char *ptr) ctx->ibuf_len=0; ctx->obuf_off=0; ctx->obuf_len=0; + if (b->next_bio == NULL) return(0); ret=BIO_ctrl(b->next_bio,cmd,num,ptr); break; case BIO_CTRL_INFO: @@ -311,19 +303,25 @@ static long buffer_ctrl(BIO *b, int cmd, long num, char *ptr) case BIO_CTRL_WPENDING: ret=(long)ctx->obuf_len; if (ret == 0) + { + if (b->next_bio == NULL) return(0); ret=BIO_ctrl(b->next_bio,cmd,num,ptr); + } break; case BIO_CTRL_PENDING: ret=(long)ctx->ibuf_len; if (ret == 0) + { + if (b->next_bio == NULL) return(0); ret=BIO_ctrl(b->next_bio,cmd,num,ptr); + } break; case BIO_C_SET_BUFF_READ_DATA: if (num > ctx->ibuf_size) { - p1=Malloc((int)num); + p1=OPENSSL_malloc((int)num); if (p1 == NULL) goto malloc_error; - if (ctx->ibuf != NULL) Free(ctx->ibuf); + if (ctx->ibuf != NULL) OPENSSL_free(ctx->ibuf); ctx->ibuf=p1; } ctx->ibuf_off=0; @@ -355,21 +353,21 @@ static long buffer_ctrl(BIO *b, int cmd, long num, char *ptr) p2=ctx->obuf; if ((ibs > DEFAULT_BUFFER_SIZE) && (ibs != ctx->ibuf_size)) { - p1=(char *)Malloc((int)num); + p1=(char *)OPENSSL_malloc((int)num); if (p1 == NULL) goto malloc_error; } if ((obs > DEFAULT_BUFFER_SIZE) && (obs != ctx->obuf_size)) { - p2=(char *)Malloc((int)num); + p2=(char *)OPENSSL_malloc((int)num); if (p2 == NULL) { - if (p1 != ctx->ibuf) Free(p1); + if (p1 != ctx->ibuf) OPENSSL_free(p1); goto malloc_error; } } if (ctx->ibuf != p1) { - Free(ctx->ibuf); + OPENSSL_free(ctx->ibuf); ctx->ibuf=p1; ctx->ibuf_off=0; ctx->ibuf_len=0; @@ -377,7 +375,7 @@ static long buffer_ctrl(BIO *b, int cmd, long num, char *ptr) } if (ctx->obuf != p2) { - Free(ctx->obuf); + OPENSSL_free(ctx->obuf); ctx->obuf=p2; ctx->obuf_off=0; ctx->obuf_len=0; @@ -385,12 +383,14 @@ static long buffer_ctrl(BIO *b, int cmd, long num, char *ptr) } break; case BIO_C_DO_STATE_MACHINE: + if (b->next_bio == NULL) return(0); BIO_clear_retry_flags(b); ret=BIO_ctrl(b->next_bio,cmd,num,ptr); BIO_copy_next_retry(b); break; case BIO_CTRL_FLUSH: + if (b->next_bio == NULL) return(0); if (ctx->obuf_len <= 0) { ret=BIO_ctrl(b->next_bio,cmd,num,ptr); @@ -429,6 +429,7 @@ fprintf(stderr,"FLUSH [%3d] %3d -> %3d\n",ctx->obuf_off,ctx->obuf_len-ctx->obuf_ ret=0; break; default: + if (b->next_bio == NULL) return(0); ret=BIO_ctrl(b->next_bio,cmd,num,ptr); break; } @@ -438,6 +439,20 @@ malloc_error: return(0); } +static long buffer_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) + { + long ret=1; + + if (b->next_bio == NULL) return(0); + switch (cmd) + { + default: + ret=BIO_callback_ctrl(b->next_bio,cmd,fp); + break; + } + return(ret); + } + static int buffer_gets(BIO *b, char *buf, int size) { BIO_F_BUFFER_CTX *ctx; @@ -489,7 +504,7 @@ static int buffer_gets(BIO *b, char *buf, int size) } } -static int buffer_puts(BIO *b, char *str) +static int buffer_puts(BIO *b, const char *str) { return(BIO_write(b,str,strlen(str))); }