Skip to content

Commit 83481f2

Browse files
danielfojtcorecode
authored andcommitted
Improve handling errors from SSL_read().
Distinguish between fatal and recoverable errors and retry the operation in the latter case.
1 parent edb7c61 commit 83481f2

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

net.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,18 @@ read_remote(int fd, int extbufsize, char *extbuf)
150150
pos = 0;
151151
if (((config.features & SECURETRANSFER) != 0) &&
152152
(config.features & NOSSL) == 0) {
153-
if ((rlen = SSL_read(config.ssl, buff + len, sizeof(buff) - len)) == -1) {
154-
strlcpy(neterr, ssl_errstr(), sizeof(neterr));
155-
goto error;
153+
if ((rlen = SSL_read(config.ssl, buff + len, sizeof(buff) - len)) <= 0) {
154+
switch (SSL_get_error(config.ssl, rlen)) {
155+
case SSL_ERROR_ZERO_RETURN:
156+
case SSL_ERROR_SYSCALL:
157+
case SSL_ERROR_SSL:
158+
strlcpy(neterr, ssl_errstr(), sizeof(neterr));
159+
goto error;
160+
default:
161+
/* in case of recoverable error, retry after short sleep */
162+
usleep(10000);
163+
continue;
164+
}
156165
}
157166
} else {
158167
if ((rlen = read(fd, buff + len, sizeof(buff) - len)) == -1) {

0 commit comments

Comments
 (0)