diff --git a/crypto/asn1/a_d2i_fp.c b/crypto/asn1/a_d2i_fp.c index 3da6df9b..50779d2b 100644 --- a/crypto/asn1/a_d2i_fp.c +++ b/crypto/asn1/a_d2i_fp.c @@ -69,15 +69,12 @@ static int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb); void *ASN1_d2i_fp(void *(*xnew) (void), d2i_of_void *d2i, FILE *in, void **x) { - BIO *b; - void *ret; - - if ((b = BIO_new(BIO_s_file())) == NULL) { + BIO *b = BIO_new_fp(in, BIO_NOCLOSE); + if (b == NULL) { OPENSSL_PUT_ERROR(ASN1, ERR_R_BUF_LIB); - return (NULL); + return NULL; } - BIO_set_fp(b, in, BIO_NOCLOSE); - ret = ASN1_d2i_bio(xnew, d2i, b, x); + void *ret = ASN1_d2i_bio(xnew, d2i, b, x); BIO_free(b); return (ret); } @@ -126,17 +123,14 @@ void *ASN1_item_d2i_bio(const ASN1_ITEM *it, BIO *in, void *x) #ifndef OPENSSL_NO_FP_API void *ASN1_item_d2i_fp(const ASN1_ITEM *it, FILE *in, void *x) { - BIO *b; - char *ret; - - if ((b = BIO_new(BIO_s_file())) == NULL) { + BIO *b = BIO_new_fp(in, BIO_NOCLOSE); + if (b == NULL) { OPENSSL_PUT_ERROR(ASN1, ERR_R_BUF_LIB); - return (NULL); + return NULL; } - BIO_set_fp(b, in, BIO_NOCLOSE); - ret = ASN1_item_d2i_bio(it, b, x); + void *ret = ASN1_item_d2i_bio(it, b, x); BIO_free(b); - return (ret); + return ret; } #endif diff --git a/crypto/asn1/a_i2d_fp.c b/crypto/asn1/a_i2d_fp.c index 7b76d0c5..5cc97d2a 100644 --- a/crypto/asn1/a_i2d_fp.c +++ b/crypto/asn1/a_i2d_fp.c @@ -61,17 +61,14 @@ int ASN1_i2d_fp(i2d_of_void *i2d, FILE *out, void *x) { - BIO *b; - int ret; - - if ((b = BIO_new(BIO_s_file())) == NULL) { + BIO *b = BIO_new_fp(out, BIO_NOCLOSE); + if (b == NULL) { OPENSSL_PUT_ERROR(ASN1, ERR_R_BUF_LIB); - return (0); + return 0; } - BIO_set_fp(b, out, BIO_NOCLOSE); - ret = ASN1_i2d_bio(i2d, b, x); + int ret = ASN1_i2d_bio(i2d, b, x); BIO_free(b); - return (ret); + return ret; } int ASN1_i2d_bio(i2d_of_void *i2d, BIO *out, void *x) @@ -110,17 +107,14 @@ int ASN1_i2d_bio(i2d_of_void *i2d, BIO *out, void *x) int ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, void *x) { - BIO *b; - int ret; - - if ((b = BIO_new(BIO_s_file())) == NULL) { + BIO *b = BIO_new_fp(out, BIO_NOCLOSE); + if (b == NULL) { OPENSSL_PUT_ERROR(ASN1, ERR_R_BUF_LIB); - return (0); + return 0; } - BIO_set_fp(b, out, BIO_NOCLOSE); - ret = ASN1_item_i2d_bio(it, b, x); + int ret = ASN1_item_i2d_bio(it, b, x); BIO_free(b); - return (ret); + return ret; } int ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, void *x) diff --git a/crypto/bio/file.c b/crypto/bio/file.c index 6a0b9a99..a177763f 100644 --- a/crypto/bio/file.c +++ b/crypto/bio/file.c @@ -107,13 +107,12 @@ BIO *BIO_new_file(const char *filename, const char *mode) { return NULL; } - ret = BIO_new(BIO_s_file()); + ret = BIO_new_fp(file, BIO_CLOSE); if (ret == NULL) { fclose(file); return NULL; } - BIO_set_fp(ret, file, BIO_CLOSE); return ret; } diff --git a/crypto/bn_extra/convert.c b/crypto/bn_extra/convert.c index c70ff8b5..9a1a69e3 100644 --- a/crypto/bn_extra/convert.c +++ b/crypto/bn_extra/convert.c @@ -367,17 +367,13 @@ end: } int BN_print_fp(FILE *fp, const BIGNUM *a) { - BIO *b; - int ret; - - b = BIO_new(BIO_s_file()); + BIO *b = BIO_new_fp(fp, BIO_NOCLOSE); if (b == NULL) { return 0; } - BIO_set_fp(b, fp, BIO_NOCLOSE); - ret = BN_print(b, a); - BIO_free(b); + int ret = BN_print(b, a); + BIO_free(b); return ret; } diff --git a/crypto/pem/pem_info.c b/crypto/pem/pem_info.c index d707e426..ba29b833 100644 --- a/crypto/pem/pem_info.c +++ b/crypto/pem/pem_info.c @@ -75,17 +75,14 @@ STACK_OF(X509_INFO) *PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u) { - BIO *b; - STACK_OF(X509_INFO) *ret; - - if ((b = BIO_new(BIO_s_file())) == NULL) { + BIO *b = BIO_new_fp(fp, BIO_NOCLOSE); + if (b == NULL) { OPENSSL_PUT_ERROR(PEM, ERR_R_BUF_LIB); - return (0); + return 0; } - BIO_set_fp(b, fp, BIO_NOCLOSE); - ret = PEM_X509_INFO_read_bio(b, sk, cb, u); + STACK_OF(X509_INFO) *ret = PEM_X509_INFO_read_bio(b, sk, cb, u); BIO_free(b); - return (ret); + return ret; } #endif diff --git a/crypto/pem/pem_lib.c b/crypto/pem/pem_lib.c index 5180e55d..759c5d7e 100644 --- a/crypto/pem/pem_lib.c +++ b/crypto/pem/pem_lib.c @@ -121,17 +121,14 @@ void PEM_dek_info(char *buf, const char *type, int len, char *str) void *PEM_ASN1_read(d2i_of_void *d2i, const char *name, FILE *fp, void **x, pem_password_cb *cb, void *u) { - BIO *b; - void *ret; - - if ((b = BIO_new(BIO_s_file())) == NULL) { + BIO *b = BIO_new_fp(fp, BIO_NOCLOSE); + if (b == NULL) { OPENSSL_PUT_ERROR(PEM, ERR_R_BUF_LIB); - return (0); + return NULL; } - BIO_set_fp(b, fp, BIO_NOCLOSE); - ret = PEM_ASN1_read_bio(d2i, name, b, x, cb, u); + void *ret = PEM_ASN1_read_bio(d2i, name, b, x, cb, u); BIO_free(b); - return (ret); + return ret; } #endif @@ -257,17 +254,14 @@ int PEM_ASN1_write(i2d_of_void *i2d, const char *name, FILE *fp, void *x, const EVP_CIPHER *enc, unsigned char *kstr, int klen, pem_password_cb *callback, void *u) { - BIO *b; - int ret; - - if ((b = BIO_new(BIO_s_file())) == NULL) { + BIO *b = BIO_new_fp(fp, BIO_NOCLOSE); + if (b == NULL) { OPENSSL_PUT_ERROR(PEM, ERR_R_BUF_LIB); - return (0); + return 0; } - BIO_set_fp(b, fp, BIO_NOCLOSE); - ret = PEM_ASN1_write_bio(i2d, name, b, x, enc, kstr, klen, callback, u); + int ret = PEM_ASN1_write_bio(i2d, name, b, x, enc, kstr, klen, callback, u); BIO_free(b); - return (ret); + return ret; } #endif @@ -514,15 +508,12 @@ static int load_iv(char **fromp, unsigned char *to, int num) int PEM_write(FILE *fp, const char *name, const char *header, const unsigned char *data, long len) { - BIO *b; - int ret; - - if ((b = BIO_new(BIO_s_file())) == NULL) { + BIO *b = BIO_new_fp(fp, BIO_NOCLOSE); + if (b == NULL) { OPENSSL_PUT_ERROR(PEM, ERR_R_BUF_LIB); - return (0); + return 0; } - BIO_set_fp(b, fp, BIO_NOCLOSE); - ret = PEM_write_bio(b, name, header, data, len); + int ret = PEM_write_bio(b, name, header, data, len); BIO_free(b); return (ret); } @@ -588,15 +579,12 @@ int PEM_write_bio(BIO *bp, const char *name, const char *header, int PEM_read(FILE *fp, char **name, char **header, unsigned char **data, long *len) { - BIO *b; - int ret; - - if ((b = BIO_new(BIO_s_file())) == NULL) { + BIO *b = BIO_new_fp(fp, BIO_NOCLOSE); + if (b == NULL) { OPENSSL_PUT_ERROR(PEM, ERR_R_BUF_LIB); - return (0); + return 0; } - BIO_set_fp(b, fp, BIO_NOCLOSE); - ret = PEM_read_bio(b, name, header, data, len); + int ret = PEM_read_bio(b, name, header, data, len); BIO_free(b); return (ret); } diff --git a/crypto/pem/pem_pkey.c b/crypto/pem/pem_pkey.c index 9fbaeef8..725a84be 100644 --- a/crypto/pem/pem_pkey.c +++ b/crypto/pem/pem_pkey.c @@ -155,31 +155,26 @@ int PEM_write_bio_PrivateKey(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc, EVP_PKEY *PEM_read_PrivateKey(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, void *u) { - BIO *b; - EVP_PKEY *ret; - - if ((b = BIO_new(BIO_s_file())) == NULL) { + BIO *b = BIO_new_fp(fp, BIO_NOCLOSE); + if (b == NULL) { OPENSSL_PUT_ERROR(PEM, ERR_R_BUF_LIB); - return (0); + return NULL; } - BIO_set_fp(b, fp, BIO_NOCLOSE); - ret = PEM_read_bio_PrivateKey(b, x, cb, u); + EVP_PKEY *ret = PEM_read_bio_PrivateKey(b, x, cb, u); BIO_free(b); - return (ret); + return ret; } int PEM_write_PrivateKey(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc, unsigned char *kstr, int klen, pem_password_cb *cb, void *u) { - BIO *b; - int ret; - - if ((b = BIO_new_fp(fp, BIO_NOCLOSE)) == NULL) { + BIO *b = BIO_new_fp(fp, BIO_NOCLOSE); + if (b == NULL) { OPENSSL_PUT_ERROR(PEM, ERR_R_BUF_LIB); return 0; } - ret = PEM_write_bio_PrivateKey(b, x, enc, kstr, klen, cb, u); + int ret = PEM_write_bio_PrivateKey(b, x, enc, kstr, klen, cb, u); BIO_free(b); return ret; } @@ -212,16 +207,13 @@ DH *PEM_read_bio_DHparams(BIO *bp, DH **x, pem_password_cb *cb, void *u) #ifndef OPENSSL_NO_FP_API DH *PEM_read_DHparams(FILE *fp, DH **x, pem_password_cb *cb, void *u) { - BIO *b; - DH *ret; - - if ((b = BIO_new(BIO_s_file())) == NULL) { + BIO *b = BIO_new_fp(fp, BIO_NOCLOSE); + if (b == NULL) { OPENSSL_PUT_ERROR(PEM, ERR_R_BUF_LIB); - return (0); + return NULL; } - BIO_set_fp(b, fp, BIO_NOCLOSE); - ret = PEM_read_bio_DHparams(b, x, cb, u); + DH *ret = PEM_read_bio_DHparams(b, x, cb, u); BIO_free(b); - return (ret); + return ret; } #endif diff --git a/crypto/x509/t_crl.c b/crypto/x509/t_crl.c index 6c347cb8..dc9b87f8 100644 --- a/crypto/x509/t_crl.c +++ b/crypto/x509/t_crl.c @@ -64,17 +64,14 @@ #ifndef OPENSSL_NO_FP_API int X509_CRL_print_fp(FILE *fp, X509_CRL *x) { - BIO *b; - int ret; - - if ((b = BIO_new(BIO_s_file())) == NULL) { + BIO *b = BIO_new_fp(fp, BIO_NOCLOSE); + if (b == NULL) { OPENSSL_PUT_ERROR(X509, ERR_R_BUF_LIB); - return (0); + return 0; } - BIO_set_fp(b, fp, BIO_NOCLOSE); - ret = X509_CRL_print(b, x); + int ret = X509_CRL_print(b, x); BIO_free(b); - return (ret); + return ret; } #endif diff --git a/crypto/x509/t_req.c b/crypto/x509/t_req.c index 39c836cc..2fd36f8c 100644 --- a/crypto/x509/t_req.c +++ b/crypto/x509/t_req.c @@ -65,13 +65,11 @@ int X509_REQ_print_fp(FILE *fp, X509_REQ *x) { - BIO *bio = BIO_new(BIO_s_file()); + BIO *bio = BIO_new_fp(fp, BIO_NOCLOSE); if (bio == NULL) { OPENSSL_PUT_ERROR(X509, ERR_R_BUF_LIB); return 0; } - - BIO_set_fp(bio, fp, BIO_NOCLOSE); int ret = X509_REQ_print(bio, x); BIO_free(bio); return ret; diff --git a/crypto/x509/t_x509.c b/crypto/x509/t_x509.c index 3339523c..e45a7659 100644 --- a/crypto/x509/t_x509.c +++ b/crypto/x509/t_x509.c @@ -72,17 +72,14 @@ int X509_print_ex_fp(FILE *fp, X509 *x, unsigned long nmflag, unsigned long cflag) { - BIO *b; - int ret; - - if ((b = BIO_new(BIO_s_file())) == NULL) { + BIO *b = BIO_new_fp(fp, BIO_NOCLOSE); + if (b == NULL) { OPENSSL_PUT_ERROR(X509, ERR_R_BUF_LIB); - return (0); + return 0; } - BIO_set_fp(b, fp, BIO_NOCLOSE); - ret = X509_print_ex(b, x, nmflag, cflag); + int ret = X509_print_ex(b, x, nmflag, cflag); BIO_free(b); - return (ret); + return ret; } int X509_print_fp(FILE *fp, X509 *x)