From 5844ef27aa46cba3d343035ccd35b03525db9843 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 26 Jan 2024 14:27:16 +0100 Subject: [PATCH] s4:lib/tls: remove tstream_tls_push_trigger_write step At the time of https://bugzilla.samba.org/show_bug.cgi?id=7218, we tested this versions: 2.4.1 -> broken 2.4.2 -> broken 2.6.0 -> broken 2.8.0 -> broken 2.8.1 -> broken 2.8.2 -> OK 2.8.3 -> OK 2.8.4 -> OK 2.8.5 -> OK 2.8.6 -> OK 2.10.0 -> broken 2.10.1 -> broken 2.10.2 -> OK These seemed to be the fixes in gnutls upstream. Change 2.8.1 -> 2.8.2: http://git.savannah.gnu.org/gitweb/?p=gnutls.git;a=commitdiff;h=28fb34099edaf62e5472cc6e5e2749fed369ea01 Change 2.10.1 -> 2.10.2: http://git.savannah.gnu.org/gitweb/?p=gnutls.git;a=commitdiff;h=0d07d8432d57805a8354ebd6c1e7829f3ab159cb This shouldn't be a problem with recent (>= 3.6) versions of gnutls. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15621 Signed-off-by: Stefan Metzmacher Reviewed-by: Andrew Bartlett --- source4/lib/tls/tls_tstream.c | 61 +++-------------------------------- 1 file changed, 5 insertions(+), 56 deletions(-) diff --git a/source4/lib/tls/tls_tstream.c b/source4/lib/tls/tls_tstream.c index 41fd6cce5e3..085da5e6473 100644 --- a/source4/lib/tls/tls_tstream.c +++ b/source4/lib/tls/tls_tstream.c @@ -75,7 +75,6 @@ struct tstream_tls { off_t ofs; struct iovec iov; struct tevent_req *subreq; - struct tevent_immediate *im; } push; struct { @@ -160,9 +159,7 @@ static void tstream_tls_retry_trigger(struct tevent_context *ctx, tstream_tls_retry(stream, true); } -static void tstream_tls_push_trigger_write(struct tevent_context *ev, - struct tevent_immediate *im, - void *private_data); +static void tstream_tls_push_done(struct tevent_req *subreq); static ssize_t tstream_tls_push_function(gnutls_transport_ptr_t ptr, const void *buf, size_t size) @@ -173,6 +170,7 @@ static ssize_t tstream_tls_push_function(gnutls_transport_ptr_t ptr, struct tstream_tls *tlss = tstream_context_data(stream, struct tstream_tls); + struct tevent_req *subreq = NULL; uint8_t *nbuf; size_t len; @@ -206,56 +204,7 @@ static ssize_t tstream_tls_push_function(gnutls_transport_ptr_t ptr, tlss->push.buf = nbuf; memcpy(tlss->push.buf + tlss->push.ofs, buf, len); - - if (tlss->push.im == NULL) { - tlss->push.im = tevent_create_immediate(tlss); - if (tlss->push.im == NULL) { - errno = ENOMEM; - return -1; - } - } - - if (tlss->push.ofs == 0) { - /* - * We'll do start the tstream_writev - * in the next event cycle. - * - * This way we can batch all push requests, - * if they fit into a UINT16_MAX buffer. - * - * This is important as gnutls_handshake() - * had a bug in some versions e.g. 2.4.1 - * and others (See bug #7218) and it doesn't - * handle EAGAIN. - */ - tevent_schedule_immediate(tlss->push.im, - tlss->current_ev, - tstream_tls_push_trigger_write, - stream); - } - tlss->push.ofs += len; - return len; -} - -static void tstream_tls_push_done(struct tevent_req *subreq); - -static void tstream_tls_push_trigger_write(struct tevent_context *ev, - struct tevent_immediate *im, - void *private_data) -{ - struct tstream_context *stream = - talloc_get_type_abort(private_data, - struct tstream_context); - struct tstream_tls *tlss = - tstream_context_data(stream, - struct tstream_tls); - struct tevent_req *subreq; - - if (tlss->push.subreq) { - /* nothing todo */ - return; - } tlss->push.iov.iov_base = (char *)tlss->push.buf; tlss->push.iov.iov_len = tlss->push.ofs; @@ -265,13 +214,13 @@ static void tstream_tls_push_trigger_write(struct tevent_context *ev, tlss->plain_stream, &tlss->push.iov, 1); if (subreq == NULL) { - tlss->error = ENOMEM; - tstream_tls_retry(stream, false); - return; + errno = ENOMEM; + return -1; } tevent_req_set_callback(subreq, tstream_tls_push_done, stream); tlss->push.subreq = subreq; + return len; } static void tstream_tls_push_done(struct tevent_req *subreq)