summaryrefslogtreecommitdiff
path: root/src/lib/libssl/bio_ssl.c
diff options
context:
space:
mode:
authorjsing <>2014-06-08 14:43:57 +0000
committerjsing <>2014-06-08 14:43:57 +0000
commit0dd57e34be7e25a7d1f09fccc6c9487405424ca5 (patch)
tree7bceb70f1e953c61edae7500d0892a5d8bc1ac19 /src/lib/libssl/bio_ssl.c
parentb0da9db60669f98a52f338ea5655182f0d65d7e2 (diff)
downloadopenbsd-0dd57e34be7e25a7d1f09fccc6c9487405424ca5.tar.gz
openbsd-0dd57e34be7e25a7d1f09fccc6c9487405424ca5.tar.bz2
openbsd-0dd57e34be7e25a7d1f09fccc6c9487405424ca5.zip
Clean up BIO_free() handling in bio_ssl.c - BIO_free() has its own NULL
check, so do not duplicate it here. Make the error handling consistent by always using 'goto err' rather than returning in certain cases. Also add a missing BIO_free(ssl) in BIO_new_ssl_connect(). ok deraadt@
Diffstat (limited to 'src/lib/libssl/bio_ssl.c')
-rw-r--r--src/lib/libssl/bio_ssl.c29
1 files changed, 16 insertions, 13 deletions
diff --git a/src/lib/libssl/bio_ssl.c b/src/lib/libssl/bio_ssl.c
index 3cd462e06f..649f7513b3 100644
--- a/src/lib/libssl/bio_ssl.c
+++ b/src/lib/libssl/bio_ssl.c
@@ -494,17 +494,16 @@ BIO_new_buffer_ssl_connect(SSL_CTX *ctx)
494 BIO *ret = NULL, *buf = NULL, *ssl = NULL; 494 BIO *ret = NULL, *buf = NULL, *ssl = NULL;
495 495
496 if ((buf = BIO_new(BIO_f_buffer())) == NULL) 496 if ((buf = BIO_new(BIO_f_buffer())) == NULL)
497 return (NULL); 497 goto err;
498 if ((ssl = BIO_new_ssl_connect(ctx)) == NULL) 498 if ((ssl = BIO_new_ssl_connect(ctx)) == NULL)
499 goto err; 499 goto err;
500 if ((ret = BIO_push(buf, ssl)) == NULL) 500 if ((ret = BIO_push(buf, ssl)) == NULL)
501 goto err; 501 goto err;
502 return (ret); 502 return (ret);
503
503err: 504err:
504 if (buf != NULL) 505 BIO_free(buf);
505 BIO_free(buf); 506 BIO_free(ssl);
506 if (ssl != NULL)
507 BIO_free(ssl);
508 return (NULL); 507 return (NULL);
509} 508}
510 509
@@ -514,15 +513,16 @@ BIO_new_ssl_connect(SSL_CTX *ctx)
514 BIO *ret = NULL, *con = NULL, *ssl = NULL; 513 BIO *ret = NULL, *con = NULL, *ssl = NULL;
515 514
516 if ((con = BIO_new(BIO_s_connect())) == NULL) 515 if ((con = BIO_new(BIO_s_connect())) == NULL)
517 return (NULL); 516 goto err;
518 if ((ssl = BIO_new_ssl(ctx, 1)) == NULL) 517 if ((ssl = BIO_new_ssl(ctx, 1)) == NULL)
519 goto err; 518 goto err;
520 if ((ret = BIO_push(ssl, con)) == NULL) 519 if ((ret = BIO_push(ssl, con)) == NULL)
521 goto err; 520 goto err;
522 return (ret); 521 return (ret);
522
523err: 523err:
524 if (con != NULL) 524 BIO_free(con);
525 BIO_free(con); 525 BIO_free(ssl);
526 return (NULL); 526 return (NULL);
527} 527}
528 528
@@ -533,11 +533,10 @@ BIO_new_ssl(SSL_CTX *ctx, int client)
533 SSL *ssl; 533 SSL *ssl;
534 534
535 if ((ret = BIO_new(BIO_f_ssl())) == NULL) 535 if ((ret = BIO_new(BIO_f_ssl())) == NULL)
536 return (NULL); 536 goto err;
537 if ((ssl = SSL_new(ctx)) == NULL) { 537 if ((ssl = SSL_new(ctx)) == NULL)
538 BIO_free(ret); 538 goto err;
539 return (NULL); 539
540 }
541 if (client) 540 if (client)
542 SSL_set_connect_state(ssl); 541 SSL_set_connect_state(ssl);
543 else 542 else
@@ -545,6 +544,10 @@ BIO_new_ssl(SSL_CTX *ctx, int client)
545 544
546 BIO_set_ssl(ret, ssl, BIO_CLOSE); 545 BIO_set_ssl(ret, ssl, BIO_CLOSE);
547 return (ret); 546 return (ret);
547
548err:
549 BIO_free(ret);
550 return (NULL);
548} 551}
549 552
550int 553int