Skip to content

Commit 9a7f6f3

Browse files
committed
tls-openssl.c: Handle errors in read/write operations
Openssl functions return values <= 0, so we have to handle them separately to process the errors later together in the same code segment.
1 parent ca92bf7 commit 9a7f6f3

1 file changed

Lines changed: 34 additions & 2 deletions

File tree

cups/tls-openssl.c

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,23 @@ _httpTLSRead(http_t *http, // I - Connection to server
916916
char *buf, // I - Buffer to store data
917917
int len) // I - Length of buffer
918918
{
919-
return (SSL_read((SSL *)(http->tls), buf, len));
919+
int bytes;
920+
921+
bytes = SSL_read((SSL *)(http->tls), buf, len);
922+
923+
if (bytes > 0)
924+
return (bytes);
925+
926+
/*
927+
* For now, make difference only for error after which we can retry, EPIPE otherwise...
928+
*/
929+
930+
if (SSL_get_error(http->tls, bytes) == SSL_ERROR_WANT_READ)
931+
errno = EAGAIN;
932+
else
933+
errno = EPIPE;
934+
935+
return (-1);
920936
}
921937

922938

@@ -1242,7 +1258,23 @@ _httpTLSWrite(http_t *http, // I - Connection to server
12421258
const char *buf, // I - Buffer holding data
12431259
int len) // I - Length of buffer
12441260
{
1245-
return (SSL_write(http->tls, buf, len));
1261+
int bytes;
1262+
1263+
bytes = SSL_write(http->tls, buf, len);
1264+
1265+
if (bytes > 0)
1266+
return (bytes);
1267+
1268+
/*
1269+
* For now, make difference only for error after which we can retry, EPIPE otherwise...
1270+
*/
1271+
1272+
if (SSL_get_error(http->tls, bytes) == SSL_ERROR_WANT_WRITE)
1273+
errno = EAGAIN;
1274+
else
1275+
errno = EPIPE;
1276+
1277+
return (-1);
12461278
}
12471279

12481280

0 commit comments

Comments
 (0)