diff options
author | Nikos Mavrogiannopoulos | 2010-08-17 19:04:34 +0200 |
---|---|---|
committer | Nikos Mavrogiannopoulos | 2010-08-18 20:41:36 +0200 |
commit | 368b5740dd89c160645548b3a608e032d1d39160 (patch) | |
tree | 9accfaccd8378f4ae811a47835e511ef8866abc4 /src/gnutls_io.c | |
parent | 7fec961893adf880d4acc3da171031829f93af86 (diff) |
Safer usage of session variable to prevent segmentation faults on closure. Should solve issue #106.
Diffstat (limited to 'src/gnutls_io.c')
-rw-r--r-- | src/gnutls_io.c | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/src/gnutls_io.c b/src/gnutls_io.c index 8187da6..ba03fce 100644 --- a/src/gnutls_io.c +++ b/src/gnutls_io.c | |||
@@ -221,6 +221,10 @@ static apr_status_t gnutls_io_input_read(mgs_handle_t * ctxt, | |||
221 | ctxt->input_block = APR_NONBLOCK_READ; | 221 | ctxt->input_block = APR_NONBLOCK_READ; |
222 | } | 222 | } |
223 | } | 223 | } |
224 | |||
225 | if (ctxt->session == NULL) { | ||
226 | return APR_EGENERAL; | ||
227 | } | ||
224 | 228 | ||
225 | while (1) { | 229 | while (1) { |
226 | 230 | ||
@@ -360,7 +364,7 @@ static int gnutls_do_handshake(mgs_handle_t * ctxt) | |||
360 | int errcode; | 364 | int errcode; |
361 | int maxtries = HANDSHAKE_MAX_TRIES; | 365 | int maxtries = HANDSHAKE_MAX_TRIES; |
362 | 366 | ||
363 | if (ctxt->status != 0) { | 367 | if (ctxt->status != 0 || ctxt->session == NULL) { |
364 | return -1; | 368 | return -1; |
365 | } | 369 | } |
366 | 370 | ||
@@ -441,6 +445,9 @@ tryagain: | |||
441 | int mgs_rehandshake(mgs_handle_t * ctxt) | 445 | int mgs_rehandshake(mgs_handle_t * ctxt) |
442 | { | 446 | { |
443 | int rv; | 447 | int rv; |
448 | |||
449 | if (ctxt->session == NULL) | ||
450 | return -1; | ||
444 | 451 | ||
445 | rv = gnutls_rehandshake(ctxt->session); | 452 | rv = gnutls_rehandshake(ctxt->session); |
446 | 453 | ||
@@ -565,7 +572,7 @@ apr_status_t mgs_filter_output(ap_filter_t * f, | |||
565 | 572 | ||
566 | apr_bucket_copy(bucket, &e); | 573 | apr_bucket_copy(bucket, &e); |
567 | APR_BRIGADE_INSERT_TAIL(ctxt->output_bb, e); | 574 | APR_BRIGADE_INSERT_TAIL(ctxt->output_bb, e); |
568 | 575 | ||
569 | if ((status = ap_pass_brigade(f->next, tmpb)) != APR_SUCCESS) { | 576 | if ((status = ap_pass_brigade(f->next, tmpb)) != APR_SUCCESS) { |
570 | apr_brigade_cleanup(ctxt->output_bb); | 577 | apr_brigade_cleanup(ctxt->output_bb); |
571 | return status; | 578 | return status; |
@@ -609,10 +616,14 @@ apr_status_t mgs_filter_output(ap_filter_t * f, | |||
609 | 616 | ||
610 | if (len > 0) { | 617 | if (len > 0) { |
611 | 618 | ||
612 | do { | 619 | if (ctxt->session == NULL) { |
613 | ret = gnutls_record_send(ctxt->session, data, len); | 620 | ret = GNUTLS_E_INVALID_REQUEST; |
621 | } else { | ||
622 | do { | ||
623 | ret = gnutls_record_send(ctxt->session, data, len); | ||
624 | } | ||
625 | while(ret == GNUTLS_E_INTERRUPTED || ret == GNUTLS_E_AGAIN); | ||
614 | } | 626 | } |
615 | while(ret == GNUTLS_E_INTERRUPTED || ret == GNUTLS_E_AGAIN); | ||
616 | 627 | ||
617 | if (ret < 0) { | 628 | if (ret < 0) { |
618 | /* error sending output */ | 629 | /* error sending output */ |
@@ -674,7 +685,8 @@ ssize_t mgs_transport_read(gnutls_transport_ptr_t ptr, | |||
674 | if (APR_STATUS_IS_EOF(ctxt->input_rc)) { | 685 | if (APR_STATUS_IS_EOF(ctxt->input_rc)) { |
675 | return 0; | 686 | return 0; |
676 | } else { | 687 | } else { |
677 | gnutls_transport_set_errno(ctxt->session, EINTR); | 688 | if (ctxt->session) |
689 | gnutls_transport_set_errno(ctxt->session, EINTR); | ||
678 | return -1; | 690 | return -1; |
679 | } | 691 | } |
680 | } | 692 | } |
@@ -697,7 +709,8 @@ ssize_t mgs_transport_read(gnutls_transport_ptr_t ptr, | |||
697 | if (APR_STATUS_IS_EAGAIN(ctxt->input_rc) | 709 | if (APR_STATUS_IS_EAGAIN(ctxt->input_rc) |
698 | || APR_STATUS_IS_EINTR(ctxt->input_rc)) { | 710 | || APR_STATUS_IS_EINTR(ctxt->input_rc)) { |
699 | if (len == 0) { | 711 | if (len == 0) { |
700 | gnutls_transport_set_errno(ctxt->session, EINTR); | 712 | if (ctxt->session) |
713 | gnutls_transport_set_errno(ctxt->session, EINTR); | ||
701 | return -1; | 714 | return -1; |
702 | } | 715 | } |
703 | 716 | ||