Skip to content

Commit eb7f8fd

Browse files
committed
Ignore errno for GNU TLS read/write handlers.
1 parent 73dcbcd commit eb7f8fd

4 files changed

Lines changed: 30 additions & 8 deletions

File tree

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ v3.0.1 - YYYY-MM-DD
1212
- Updated `cupsRasterReadHeader` to validate more of the page header values.
1313
- Fixed a bug when the `ippFindXxx` and `ippSetXxx` functions were mixed
1414
(Issue #138)
15+
- Fixed error handling in the low-level TLS read/write functions.
1516

1617

1718
v3.0.0 - 2026-01-08

cups/tls-gnutls.c

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

16171617
result = gnutls_record_recv(http->tls, buf, (size_t)len);
16181618

1619-
if (result < 0 && !errno)
1619+
if (result < 0)
16201620
{
16211621
// Convert GNU TLS error to errno value...
16221622
switch (result)
@@ -2025,7 +2025,7 @@ _httpTLSWrite(http_t *http, // I - Connection to server
20252025

20262026
result = gnutls_record_send(http->tls, buf, (size_t)len);
20272027

2028-
if (result < 0 && !errno)
2028+
if (result < 0)
20292029
{
20302030
// Convert GNU TLS error to errno value...
20312031
switch (result)

cups/tls-openssl.c

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//
44
// Note: This file is included from tls.c
55
//
6-
// Copyright © 2020-2025 by OpenPrinting
6+
// Copyright © 2020-2026 by OpenPrinting
77
// Copyright © 2007-2019 by Apple Inc.
88
// Copyright © 1997-2007 by Easy Software Products, all rights reserved.
99
//
@@ -1718,9 +1718,17 @@ _httpTLSRead(http_t *http, // I - Connection to server
17181718
int bytes = SSL_read((SSL *)(http->tls), buf, len);
17191719
// Bytes read
17201720

1721-
DEBUG_printf("7_httpTLSRead(http=%p, buf=%p, len=%d) returning %d", (void *)http, (void *)buf, len, bytes);
1721+
DEBUG_printf("7_httpTLSRead(http=%p, buf=%p, len=%d) got %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,20 @@ _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 = SSL_write(http->tls, buf, len);
2065+
// Bytes written
2066+
2067+
DEBUG_printf("7_httpTLSWrite(http=%p, buf=%p, len=%d) got %d", (void *)http, (void *)buf, len, bytes);
2068+
2069+
if (bytes > 0)
2070+
return (bytes);
2071+
2072+
if (SSL_get_error(http->tls, bytes) == SSL_ERROR_WANT_WRITE)
2073+
errno = EAGAIN;
2074+
else
2075+
errno = EPIPE;
2076+
2077+
return (-1);
20572078
}
20582079

20592080

xcode/libcups.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,7 +1291,7 @@
12911291
273BF6C61333B5370022CAAB /* testcups.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = testcups.c; path = ../cups/testcups.c; sourceTree = "<group>"; };
12921292
274265BC2C08EC5200510CD4 /* oauth.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = oauth.c; path = ../cups/oauth.c; sourceTree = "<group>"; };
12931293
274265BD2C08EC5200510CD4 /* oauth.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = oauth.h; path = ../cups/oauth.h; sourceTree = "<group>"; };
1294-
274561471F545B2E000378E4 /* cupspm.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; name = cupspm.md; path = ../cups/cupspm.md; sourceTree = "<group>"; };
1294+
274561471F545B2E000378E4 /* cupspm3.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; name = cupspm3.md; path = ../cups/cupspm3.md; sourceTree = "<group>"; };
12951295
2746EBD429DCD74E006A82B1 /* testhash */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = testhash; sourceTree = BUILT_PRODUCTS_DIR; };
12961296
2746EBD729DCD79A006A82B1 /* testhash.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = testhash.c; path = ../cups/testhash.c; sourceTree = "<group>"; };
12971297
274770E02345342B0089BC31 /* testthreads */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = testthreads; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -2182,7 +2182,7 @@
21822182
children = (
21832183
72E65BDE18DCA35700097E89 /* CHANGES.md */,
21842184
72E65BDF18DCA35700097E89 /* CREDITS.md */,
2185-
274561471F545B2E000378E4 /* cupspm.md */,
2185+
274561471F545B2E000378E4 /* cupspm3.md */,
21862186
72E65BB918DC7A3600097E89 /* doc */,
21872187
72E65BE018DCA35700097E89 /* INSTALL.md */,
21882188
72E65BE218DCA35700097E89 /* LICENSE */,

0 commit comments

Comments
 (0)