diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2016-12-02 00:04:30 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2016-12-02 00:04:30 +0000 |
commit | db3aa47688fa38d4edd6563ce350577617e71a27 (patch) | |
tree | fc18e3dacc91d172f18fc29f4def756689fcde99 /src/sbearssl | |
parent | 880f2a22304b393b43397c3ec8de83052a2584ce (diff) | |
download | s6-networking-db3aa47688fa38d4edd6563ce350577617e71a27.tar.xz |
Fix closing bugs in sbearssl_run and tls_run
Diffstat (limited to 'src/sbearssl')
-rw-r--r-- | src/sbearssl/sbearssl_run.c | 39 |
1 files changed, 28 insertions, 11 deletions
diff --git a/src/sbearssl/sbearssl_run.c b/src/sbearssl/sbearssl_run.c index efd711c..e4d49fa 100644 --- a/src/sbearssl/sbearssl_run.c +++ b/src/sbearssl/sbearssl_run.c @@ -18,6 +18,7 @@ int sbearssl_run (br_ssl_engine_context *ctx, int *fds, unsigned int verbosity, { iopause_fd x[4] ; unsigned int xindex[4] ; + int markedforflush = 0 ; if (ndelay_on(fds[2]) < 0 || ndelay_on(fds[3]) < 0) strerr_diefu1sys(111, "set fds non-blocking") ; @@ -31,6 +32,8 @@ int sbearssl_run (br_ssl_engine_context *ctx, int *fds, unsigned int verbosity, unsigned int state = br_ssl_engine_current_state(ctx) ; int r ; + if (state & BR_SSL_CLOSED) break ; + tain_add_g(&deadline, fds[0] >= 0 && fds[2] >= 0 && state & (BR_SSL_SENDAPP | BR_SSL_RECVREC) ? tto : &tain_infinite_relative) ; if (fds[0] >= 0 && state & BR_SSL_SENDAPP) @@ -92,11 +95,11 @@ int sbearssl_run (br_ssl_engine_context *ctx, int *fds, unsigned int verbosity, else { br_ssl_engine_recvapp_ack(ctx, w) ; - state = br_ssl_engine_current_state(ctx) ; if (fds[2] < 0 && w == len) { fd_close(fds[1]) ; fds[1] = -1 ; } + state = br_ssl_engine_current_state(ctx) ; } } @@ -116,42 +119,56 @@ int sbearssl_run (br_ssl_engine_context *ctx, int *fds, unsigned int verbosity, else { br_ssl_engine_sendrec_ack(ctx, w) ; - state = br_ssl_engine_current_state(ctx) ; if (fds[0] < 0 && w == len) { - if (options & 1) shutdown(fds[3], SHUT_WR) ; - fd_close(fds[3]) ; fds[3] = -1 ; + if (options & 1) + { + shutdown(fds[3], SHUT_WR) ; + fd_close(fds[3]) ; fds[3] = -1 ; + } + else br_ssl_engine_close(ctx) ; } + state = br_ssl_engine_current_state(ctx) ; } } /* Fill from local */ - if (state & BR_SSL_SENDAPP && x[xindex[0]].events & x[xindex[0]].revents & IOPAUSE_READ) + if (state & BR_SSL_SENDAPP && x[xindex[0]].events & IOPAUSE_READ && (markedforflush || x[xindex[0]].revents & IOPAUSE_READ)) { size_t len ; unsigned char *s = br_ssl_engine_sendapp_buf(ctx, &len) ; size_t w = allread(fds[0], (char *)s, len) ; if (!w) { + br_ssl_engine_flush(ctx, 0) ; + markedforflush = 0 ; if (!error_isagain(errno)) { fd_close(fds[0]) ; fds[0] = -1 ; - if (fds[2] >= 0) br_ssl_engine_close(ctx) ; if (!br_ssl_engine_sendrec_buf(ctx, &len)) { - if (options & 1) shutdown(fds[3], SHUT_WR) ; - fd_close(fds[3]) ; fds[3] = -1 ; + if (options & 1) + { + shutdown(fds[3], SHUT_WR) ; + fd_close(fds[3]) ; fds[3] = -1 ; + } + else br_ssl_engine_close(ctx) ; } } } else { br_ssl_engine_sendapp_ack(ctx, w) ; - br_ssl_engine_flush(ctx, 0) ; - state = br_ssl_engine_current_state(ctx) ; + if (w == len) markedforflush = 1 ; + else + { + br_ssl_engine_flush(ctx, 0) ; + markedforflush = 0 ; + } } + state = br_ssl_engine_current_state(ctx) ; } @@ -168,7 +185,7 @@ int sbearssl_run (br_ssl_engine_context *ctx, int *fds, unsigned int verbosity, { if (options & 1) shutdown(fds[2], SHUT_RD) ; fd_close(fds[2]) ; fds[2] = -1 ; - if (!br_ssl_engine_recvapp_buf(ctx, &len)) + if (fds[1] >= 0 && !br_ssl_engine_recvapp_buf(ctx, &len)) { fd_close(fds[1]) ; fds[1] = -1 ; } |