]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
tls-openssl.c: Handle errors in read/write operations 1506/head
authorZdenek Dohnal <zdohnal@redhat.com>
Wed, 4 Mar 2026 13:35:26 +0000 (14:35 +0100)
committerZdenek Dohnal <zdohnal@redhat.com>
Wed, 4 Mar 2026 13:35:26 +0000 (14:35 +0100)
Openssl functions return values <= 0, so we have to handle them
separately to process the errors later together in the same code
segment.

cups/tls-openssl.c

index 2886a3aa8fd9f611be50a3c18c6281cde02d7074..28907c9a589327ab1cd39d23f6826dc4dd5d5a2f 100644 (file)
@@ -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);
 }