Skip to content

Commit 9e76531

Browse files
committed
JNI: Check read/write return values in SSLAppData interrupt pipe helpers
1 parent d0c152f commit 9e76531

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

native/com_wolfssl_WolfSSLSession.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,9 @@ static void writeToInterruptPipe(SSLAppData* appData)
222222
{
223223
if (appData != NULL) {
224224
if (appData->interruptFds[1] != -1) {
225-
write(appData->interruptFds[1], "1", 1);
225+
if (write(appData->interruptFds[1], "1", 1) < 0) {
226+
/* Interrupt pipe wakeup is best-effort; ignore failure. */
227+
}
226228
}
227229
}
228230
}
@@ -896,9 +898,10 @@ static int socketSelect(SSLAppData* appData, int sockfd, int timeout_ms, int rx,
896898
* an error if not there. Another read/write() may have
897899
* already read it off. We just want to be interrupted,
898900
* byte value does not matter. */
901+
ssize_t rd;
899902
do {
900-
read(appData->interruptFds[0], tmpBuf, 1);
901-
} while (errno == EINTR);
903+
rd = read(appData->interruptFds[0], tmpBuf, 1);
904+
} while (rd < 0 && errno == EINTR);
902905

903906
return WOLFJNI_IO_EVENT_FD_CLOSED;
904907
}
@@ -1000,9 +1003,10 @@ static int socketPoll(SSLAppData* appData, int sockfd, int timeout_ms,
10001003
(fds[1].revents & POLLIN)) {
10011004
/* received data on interrupt pipe, read and return
10021005
* that descriptor is closed (closing) */
1006+
ssize_t rd;
10031007
do {
1004-
read(appData->interruptFds[0], tmpBuf, 1);
1005-
} while (errno == EINTR);
1008+
rd = read(appData->interruptFds[0], tmpBuf, 1);
1009+
} while (rd < 0 && errno == EINTR);
10061010

10071011
return WOLFJNI_IO_EVENT_FD_CLOSED;
10081012
}

0 commit comments

Comments
 (0)