From fdddba24b86f0f6f43510b92575660808440db91 Mon Sep 17 00:00:00 2001 From: Gerhard Rieger Date: Sun, 23 Jun 2024 20:47:12 +0200 Subject: [PATCH] Fixed hanging of OpenSSL due to nested xioclose() --- CHANGES | 3 +++ xioclose.c | 11 +++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index d38783e..4f2bd96 100644 --- a/CHANGES +++ b/CHANGES @@ -4,6 +4,9 @@ Corrections: Thanks to Kush Upadhyay from Amazon Bottlerocket team for providing the patch. + In some situations xioclose() was called nested what could cause hanging + of OpenSSL in pthread_rwlock_wrlock() + Features: Total inactivity timeout option -T 0 now means 0.0 seconds; up to version 1.8.0.0 it meant no total inactivity timeout. diff --git a/xioclose.c b/xioclose.c index 8fefe16..12ca7f1 100644 --- a/xioclose.c +++ b/xioclose.c @@ -23,6 +23,11 @@ int xioclose1(struct single *pipe) { return -1; } + if (pipe->tag == XIO_TAG_CLOSED) { + return 0; + } + pipe->tag |= XIO_TAG_CLOSED; + #if WITH_READLINE if ((pipe->dtype & XIODATA_MASK) == XIODATA_READLINE) { Write_history(pipe->para.readline.history_file); @@ -112,7 +117,6 @@ int xioclose1(struct single *pipe) { free(pipe->unlink_close); } - pipe->tag |= XIO_TAG_CLOSED; return 0; /*! */ } @@ -126,11 +130,14 @@ int xioclose(xiofile_t *file) { errno = EINVAL; return -1; } + if (file->tag == XIO_TAG_CLOSED) { + return 0; + } if (file->tag == XIO_TAG_DUAL) { + file->tag |= XIO_TAG_CLOSED; result = xioclose1(file->dual.stream[0]); result |= xioclose1(file->dual.stream[1]); - file->tag |= XIO_TAG_CLOSED; } else { result = xioclose1(&file->stream); }