diff options
| author | beck <> | 2000-12-15 02:58:47 +0000 |
|---|---|---|
| committer | beck <> | 2000-12-15 02:58:47 +0000 |
| commit | 9200bb13d15da4b2a23e6bc92c20e95b74aa2113 (patch) | |
| tree | 5c52d628ec1e34be76e7ef2a4235d248b7c44d24 /src/lib/libcrypto/bio/bio_lib.c | |
| parent | e131d25072e3d4197ba4b9bcc0d1b27d34d6488d (diff) | |
| download | openbsd-9200bb13d15da4b2a23e6bc92c20e95b74aa2113.tar.gz openbsd-9200bb13d15da4b2a23e6bc92c20e95b74aa2113.tar.bz2 openbsd-9200bb13d15da4b2a23e6bc92c20e95b74aa2113.zip | |
openssl-engine-0.9.6 merge
Diffstat (limited to 'src/lib/libcrypto/bio/bio_lib.c')
| -rw-r--r-- | src/lib/libcrypto/bio/bio_lib.c | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/src/lib/libcrypto/bio/bio_lib.c b/src/lib/libcrypto/bio/bio_lib.c index e88dcc80f3..381afc9b8e 100644 --- a/src/lib/libcrypto/bio/bio_lib.c +++ b/src/lib/libcrypto/bio/bio_lib.c | |||
| @@ -70,7 +70,7 @@ BIO *BIO_new(BIO_METHOD *method) | |||
| 70 | { | 70 | { |
| 71 | BIO *ret=NULL; | 71 | BIO *ret=NULL; |
| 72 | 72 | ||
| 73 | ret=(BIO *)Malloc(sizeof(BIO)); | 73 | ret=(BIO *)OPENSSL_malloc(sizeof(BIO)); |
| 74 | if (ret == NULL) | 74 | if (ret == NULL) |
| 75 | { | 75 | { |
| 76 | BIOerr(BIO_F_BIO_NEW,ERR_R_MALLOC_FAILURE); | 76 | BIOerr(BIO_F_BIO_NEW,ERR_R_MALLOC_FAILURE); |
| @@ -78,7 +78,7 @@ BIO *BIO_new(BIO_METHOD *method) | |||
| 78 | } | 78 | } |
| 79 | if (!BIO_set(ret,method)) | 79 | if (!BIO_set(ret,method)) |
| 80 | { | 80 | { |
| 81 | Free(ret); | 81 | OPENSSL_free(ret); |
| 82 | ret=NULL; | 82 | ret=NULL; |
| 83 | } | 83 | } |
| 84 | return(ret); | 84 | return(ret); |
| @@ -133,10 +133,13 @@ int BIO_free(BIO *a) | |||
| 133 | 133 | ||
| 134 | if ((a->method == NULL) || (a->method->destroy == NULL)) return(1); | 134 | if ((a->method == NULL) || (a->method->destroy == NULL)) return(1); |
| 135 | ret=a->method->destroy(a); | 135 | ret=a->method->destroy(a); |
| 136 | Free(a); | 136 | OPENSSL_free(a); |
| 137 | return(1); | 137 | return(1); |
| 138 | } | 138 | } |
| 139 | 139 | ||
| 140 | void BIO_vfree(BIO *a) | ||
| 141 | { BIO_free(a); } | ||
| 142 | |||
| 140 | int BIO_read(BIO *b, void *out, int outl) | 143 | int BIO_read(BIO *b, void *out, int outl) |
| 141 | { | 144 | { |
| 142 | int i; | 145 | int i; |
| @@ -198,13 +201,7 @@ int BIO_write(BIO *b, const void *in, int inl) | |||
| 198 | 201 | ||
| 199 | if (i > 0) b->num_write+=(unsigned long)i; | 202 | if (i > 0) b->num_write+=(unsigned long)i; |
| 200 | 203 | ||
| 201 | /* This is evil and not thread safe. If the BIO has been freed, | 204 | if (cb != NULL) |
| 202 | * we must not call the callback. The only way to be able to | ||
| 203 | * determine this is the reference count which is now invalid since | ||
| 204 | * the memory has been free()ed. | ||
| 205 | */ | ||
| 206 | if (b->references <= 0) abort(); | ||
| 207 | if (cb != NULL) /* && (b->references >= 1)) */ | ||
| 208 | i=(int)cb(b,BIO_CB_WRITE|BIO_CB_RETURN,in,inl, | 205 | i=(int)cb(b,BIO_CB_WRITE|BIO_CB_RETURN,in,inl, |
| 209 | 0L,(long)i); | 206 | 0L,(long)i); |
| 210 | return(i); | 207 | return(i); |
| @@ -235,6 +232,8 @@ int BIO_puts(BIO *b, const char *in) | |||
| 235 | 232 | ||
| 236 | i=b->method->bputs(b,in); | 233 | i=b->method->bputs(b,in); |
| 237 | 234 | ||
| 235 | if (i > 0) b->num_write+=(unsigned long)i; | ||
| 236 | |||
| 238 | if (cb != NULL) | 237 | if (cb != NULL) |
| 239 | i=(int)cb(b,BIO_CB_PUTS|BIO_CB_RETURN,in,0, | 238 | i=(int)cb(b,BIO_CB_PUTS|BIO_CB_RETURN,in,0, |
| 240 | 0L,(long)i); | 239 | 0L,(long)i); |
| @@ -317,7 +316,7 @@ long BIO_ctrl(BIO *b, int cmd, long larg, void *parg) | |||
| 317 | return(ret); | 316 | return(ret); |
| 318 | } | 317 | } |
| 319 | 318 | ||
| 320 | long BIO_callback_ctrl(BIO *b, int cmd, void (*fp)()) | 319 | long BIO_callback_ctrl(BIO *b, int cmd, void (*fp)(struct bio_st *, int, const char *, int, long, long)) |
| 321 | { | 320 | { |
| 322 | long ret; | 321 | long ret; |
| 323 | long (*cb)(); | 322 | long (*cb)(); |
| @@ -419,6 +418,7 @@ BIO *BIO_find_type(BIO *bio, int type) | |||
| 419 | { | 418 | { |
| 420 | int mt,mask; | 419 | int mt,mask; |
| 421 | 420 | ||
| 421 | if(!bio) return NULL; | ||
| 422 | mask=type&0xff; | 422 | mask=type&0xff; |
| 423 | do { | 423 | do { |
| 424 | if (bio->method != NULL) | 424 | if (bio->method != NULL) |
| @@ -437,6 +437,12 @@ BIO *BIO_find_type(BIO *bio, int type) | |||
| 437 | return(NULL); | 437 | return(NULL); |
| 438 | } | 438 | } |
| 439 | 439 | ||
| 440 | BIO *BIO_next(BIO *b) | ||
| 441 | { | ||
| 442 | if(!b) return NULL; | ||
| 443 | return b->next_bio; | ||
| 444 | } | ||
| 445 | |||
| 440 | void BIO_free_all(BIO *bio) | 446 | void BIO_free_all(BIO *bio) |
| 441 | { | 447 | { |
| 442 | BIO *b; | 448 | BIO *b; |
| @@ -532,3 +538,5 @@ unsigned long BIO_number_written(BIO *bio) | |||
| 532 | if(bio) return bio->num_write; | 538 | if(bio) return bio->num_write; |
| 533 | return 0; | 539 | return 0; |
| 534 | } | 540 | } |
| 541 | |||
| 542 | IMPLEMENT_STACK_OF(BIO) | ||
