Skip to content

Commit 5336ee5

Browse files
ejohnstownphilljj
authored andcommitted
Handle a select() error in the client's peer reader
bytes held select()'s return in a word32, so a -1 became 0xFFFFFFFF and ran the read path on descriptor sets select() had left alone. The SIGWINCH handler interrupts this select, so a terminal resize reaches it. - Keep the result in an int - Retry on EINTR, report anything else - Same fix readPeer() in examples/client/client.c already carries
1 parent 7d43f9e commit 5336ee5

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

apps/wolfssh/wolfssh.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ static THREAD_RET readPeer(void* in)
572572
int ret = 0;
573573
int stop = 0;
574574
int fd = wolfSSH_get_fd(args->ssh);
575-
word32 bytes;
575+
int bytes;
576576
#ifdef USE_WINDOWS_API
577577
HANDLE stdoutHandle = GetStdHandle(STD_OUTPUT_HANDLE);
578578
#endif
@@ -619,6 +619,20 @@ static THREAD_RET readPeer(void* in)
619619
timeout.tv_sec = 1;
620620
timeout.tv_usec = 0;
621621
bytes = select(fd + 1, &readSet, NULL, &errSet, &timeout);
622+
if (bytes < 0) {
623+
#ifdef USE_WINDOWS_API
624+
if (WSAGetLastError() == WSAEINTR)
625+
continue;
626+
fprintf(stderr, "select on peer socket failed, error %d\n",
627+
WSAGetLastError());
628+
#else
629+
/* the SIGWINCH handler interrupts this select */
630+
if (errno == EINTR)
631+
continue;
632+
perror("select on peer socket failed ");
633+
#endif
634+
break;
635+
}
622636
if (bytes == 0) {
623637
/* Nothing new on the socket, but a flush in the send thread may
624638
* have already taken the peer's reply off it, so run the read

0 commit comments

Comments
 (0)