Skip to content

Commit ebd5109

Browse files
authored
Merge pull request #1506 from zdohnal/openssl-write-error-handle
tls-openssl.c: Handle errors in read/write operations
2 parents 360ccf5 + 66db189 commit ebd5109

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

cups/tls-openssl.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1720,7 +1720,15 @@ _httpTLSRead(http_t *http, // I - Connection to server
17201720

17211721
DEBUG_printf("7_httpTLSRead(http=%p, buf=%p, len=%d) returning %d", (void *)http, (void *)buf, len, bytes);
17221722

1723-
return (bytes);
1723+
if (bytes > 0)
1724+
return (bytes);
1725+
1726+
if (SSL_get_error(http->tls, bytes) == SSL_ERROR_WANT_READ)
1727+
errno = EAGAIN;
1728+
else
1729+
errno = EPIPE;
1730+
1731+
return (-1);
17241732
}
17251733

17261734

@@ -2053,7 +2061,19 @@ _httpTLSWrite(http_t *http, // I - Connection to server
20532061
const char *buf, // I - Buffer holding data
20542062
int len) // I - Length of buffer
20552063
{
2056-
return (SSL_write(http->tls, buf, len));
2064+
int bytes;
2065+
2066+
bytes = SSL_write(http->tls, buf, len);
2067+
2068+
if (bytes > 0)
2069+
return (bytes);
2070+
2071+
if (SSL_get_error(http->tls, bytes) == SSL_ERROR_WANT_WRITE)
2072+
errno = EAGAIN;
2073+
else
2074+
errno = EPIPE;
2075+
2076+
return (-1);
20572077
}
20582078

20592079

0 commit comments

Comments
 (0)