From: Zdenek Dohnal Date: Wed, 4 Mar 2026 13:35:26 +0000 (+0100) Subject: tls-openssl.c: Handle errors in read/write operations X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=66db1896d2de5b75b7eeec145676ea0b6f789aa2;p=thirdparty%2Fcups.git 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. --- diff --git a/cups/tls-openssl.c b/cups/tls-openssl.c index 2886a3aa8f..28907c9a58 100644 --- a/cups/tls-openssl.c +++ b/cups/tls-openssl.c @@ -1720,7 +1720,15 @@ _httpTLSRead(http_t *http, // I - Connection to server DEBUG_printf("7_httpTLSRead(http=%p, buf=%p, len=%d) returning %d", (void *)http, (void *)buf, len, bytes); - return (bytes); + if (bytes > 0) + return (bytes); + + if (SSL_get_error(http->tls, bytes) == SSL_ERROR_WANT_READ) + errno = EAGAIN; + else + errno = EPIPE; + + return (-1); } @@ -2053,7 +2061,19 @@ _httpTLSWrite(http_t *http, // I - Connection to server const char *buf, // I - Buffer holding data int len) // I - Length of buffer { - return (SSL_write(http->tls, buf, len)); + int bytes; + + bytes = SSL_write(http->tls, buf, len); + + if (bytes > 0) + return (bytes); + + if (SSL_get_error(http->tls, bytes) == SSL_ERROR_WANT_WRITE) + errno = EAGAIN; + else + errno = EPIPE; + + return (-1); }