add judgement for ob_read_regard_ssl/ob_write_regard_ssl because when observer is stopping, fd_ could be -1

This commit is contained in:
obdev
2023-01-28 19:32:14 +08:00
committed by ob-robot
parent ba19ba90e0
commit bec4c86e69

View File

@ -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)) {