From bec4c86e69721eb574ebe721b3b3f0cdbed0aa69 Mon Sep 17 00:00:00 2001 From: obdev Date: Sat, 28 Jan 2023 19:32:14 +0800 Subject: [PATCH] add judgement for ob_read_regard_ssl/ob_write_regard_ssl because when observer is stopping, fd_ could be -1 --- deps/oblib/src/lib/ssl/ob_ssl_config.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/deps/oblib/src/lib/ssl/ob_ssl_config.cpp b/deps/oblib/src/lib/ssl/ob_ssl_config.cpp index 53bd39a662..0a67b6990e 100644 --- a/deps/oblib/src/lib/ssl/ob_ssl_config.cpp +++ b/deps/oblib/src/lib/ssl/ob_ssl_config.cpp @@ -485,7 +485,11 @@ ssize_t ob_read_regard_ssl(int fd, void *buf, size_t nbytes) { ssize_t rbytes = 0; SSL* ssl = NULL; - if (OB_LIKELY(NULL == (ssl = gs_ssl_array[fd].ssl))) { + if (OB_UNLIKELY(fd < 0 || fd > FD_MAX)) { + COMMON_LOG(ERROR, "fd is beyond limit", K(fd)); + rbytes = -1; + errno = EINVAL; + } else if (OB_LIKELY(NULL == (ssl = gs_ssl_array[fd].ssl))) { rbytes = read(fd, buf, nbytes); } else { if (OB_UNLIKELY(0 == gs_ssl_array[fd].hand_shake_done)) { @@ -544,7 +548,11 @@ ssize_t ob_write_regard_ssl(int fd, const void *buf, size_t nbytes) { ssize_t wbytes = 0; SSL* ssl = NULL; - if (OB_LIKELY(NULL == (ssl = gs_ssl_array[fd].ssl))) { + if (OB_UNLIKELY(fd < 0 || fd > FD_MAX)) { + COMMON_LOG(ERROR, "fd is beyond limit", K(fd)); + wbytes = -1; + errno = EINVAL; + } else if (OB_LIKELY(NULL == (ssl = gs_ssl_array[fd].ssl))) { wbytes = write(fd, buf, nbytes); } else { if (OB_UNLIKELY(0 == gs_ssl_array[fd].hand_shake_done)) {