Skip to content

Commit cdd7cf4

Browse files
committed
Fix potential TLS blocking issues (Issue #1128)
1 parent d435bff commit cdd7cf4

3 files changed

Lines changed: 78 additions & 61 deletions

File tree

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Changes in CUPS v2.4.17 (YYYY-MM-DD)
1313
(Issue #1501)
1414
- Fixed an issue with the class/printer CGI name checking.
1515
- Fixed infinite loop in `http_write()` on busy print servers (Issue #827)
16+
- Fixed potential TLS blocking issues (Issue #1128)
1617
- Fixed notifier logging bug that would result in nul bytes getting into the
1718
log (Issue #1450)
1819
- Fixed possible use-after-free in `cupsdReadClient()` (Issue #1454)

cups/tls-gnutls.c

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,50 +1370,58 @@ _httpTLSStart(http_t *http) /* I - Connection to server */
13701370

13711371
char crtfile[1024], /* Certificate file */
13721372
keyfile[1024]; /* Private key file */
1373-
const char *cn, // Common name to lookup
1373+
const char *cn = NULL, // Common name to lookup
13741374
*cnptr; // Pointer into common name
13751375
int have_creds = 0; /* Have credentials? */
13761376

1377-
if (http->fields[HTTP_FIELD_HOST])
1378-
{
1379-
/*
1380-
* Use hostname for TLS upgrade...
1381-
*/
1377+
_cupsMutexLock(&tls_mutex);
13821378

1383-
strlcpy(hostname, http->fields[HTTP_FIELD_HOST], sizeof(hostname));
1384-
}
1385-
else
1379+
if (!tls_common_name)
13861380
{
1387-
/*
1388-
* Resolve hostname from connection address...
1389-
*/
1390-
1391-
http_addr_t addr; /* Connection address */
1392-
socklen_t addrlen; /* Length of address */
1381+
_cupsMutexUnlock(&tls_mutex);
13931382

1394-
addrlen = sizeof(addr);
1395-
if (getsockname(http->fd, (struct sockaddr *)&addr, &addrlen))
1383+
if (http->fields[HTTP_FIELD_HOST])
13961384
{
1397-
DEBUG_printf(("4_httpTLSStart: Unable to get socket address: %s", strerror(errno)));
1398-
hostname[0] = '\0';
1385+
/*
1386+
* Use hostname for TLS upgrade...
1387+
*/
1388+
1389+
strlcpy(hostname, http->fields[HTTP_FIELD_HOST], sizeof(hostname));
13991390
}
1400-
else if (httpAddrLocalhost(&addr))
1401-
hostname[0] = '\0';
14021391
else
14031392
{
1404-
httpAddrLookup(&addr, hostname, sizeof(hostname));
1405-
DEBUG_printf(("4_httpTLSStart: Resolved socket address to \"%s\".", hostname));
1393+
/*
1394+
* Resolve hostname from connection address...
1395+
*/
1396+
1397+
http_addr_t addr; /* Connection address */
1398+
socklen_t addrlen; /* Length of address */
1399+
1400+
addrlen = sizeof(addr);
1401+
if (getsockname(http->fd, (struct sockaddr *)&addr, &addrlen))
1402+
{
1403+
DEBUG_printf(("4_httpTLSStart: Unable to get socket address: %s", strerror(errno)));
1404+
hostname[0] = '\0';
1405+
}
1406+
else if (httpAddrLocalhost(&addr))
1407+
hostname[0] = '\0';
1408+
else
1409+
{
1410+
httpAddrLookup(&addr, hostname, sizeof(hostname));
1411+
DEBUG_printf(("4_httpTLSStart: Resolved socket address to \"%s\".", hostname));
1412+
}
14061413
}
1407-
}
14081414

1409-
if (isdigit(hostname[0] & 255) || hostname[0] == '[')
1410-
hostname[0] = '\0'; /* Don't allow numeric addresses */
1415+
if (isdigit(hostname[0] & 255) || hostname[0] == '[')
1416+
hostname[0] = '\0'; /* Don't allow numeric addresses */
14111417

1412-
_cupsMutexLock(&tls_mutex);
1418+
if (hostname[0])
1419+
cn = hostname;
14131420

1414-
if (hostname[0])
1415-
cn = hostname;
1416-
else
1421+
_cupsMutexLock(&tls_mutex);
1422+
}
1423+
1424+
if (!cn)
14171425
cn = tls_common_name;
14181426

14191427
if (cn)

cups/tls-openssl.c

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,54 +1011,62 @@ _httpTLSStart(http_t *http) // I - Connection to server
10111011
// Negotiate a TLS connection as a server
10121012
char crtfile[1024], // Certificate file
10131013
keyfile[1024]; // Private key file
1014-
const char *cn, // Common name to lookup
1014+
const char *cn = NULL, // Common name to lookup
10151015
*cnptr; // Pointer into common name
10161016
int have_creds = 0; // Have credentials?
10171017
int key_status, crt_status; // Key and certificate load status
10181018

10191019
context = SSL_CTX_new(TLS_server_method());
10201020

10211021
// Find the TLS certificate...
1022-
if (http->fields[HTTP_FIELD_HOST])
1023-
{
1024-
// Use hostname for TLS upgrade...
1025-
strlcpy(hostname, http->fields[HTTP_FIELD_HOST], sizeof(hostname));
1026-
}
1027-
else
1022+
_cupsMutexLock(&tls_mutex);
1023+
1024+
if (!tls_common_name)
10281025
{
1029-
// Resolve hostname from connection address...
1030-
http_addr_t addr; // Connection address
1031-
socklen_t addrlen; // Length of address
1026+
_cupsMutexUnlock(&tls_mutex);
10321027

1033-
addrlen = sizeof(addr);
1034-
if (getsockname(http->fd, (struct sockaddr *)&addr, &addrlen))
1028+
if (http->fields[HTTP_FIELD_HOST])
10351029
{
1036-
// Unable to get local socket address so use default...
1037-
DEBUG_printf(("4_httpTLSStart: Unable to get socket address: %s", strerror(errno)));
1038-
hostname[0] = '\0';
1039-
}
1040-
else if (httpAddrLocalhost(&addr))
1041-
{
1042-
// Local access top use default...
1043-
hostname[0] = '\0';
1030+
// Use hostname for TLS upgrade...
1031+
strlcpy(hostname, http->fields[HTTP_FIELD_HOST], sizeof(hostname));
10441032
}
10451033
else
10461034
{
1047-
// Lookup the socket address...
1048-
httpAddrLookup(&addr, hostname, sizeof(hostname));
1049-
DEBUG_printf(("4_httpTLSStart: Resolved socket address to \"%s\".", hostname));
1035+
// Resolve hostname from connection address...
1036+
http_addr_t addr; // Connection address
1037+
socklen_t addrlen; // Length of address
1038+
1039+
addrlen = sizeof(addr);
1040+
if (getsockname(http->fd, (struct sockaddr *)&addr, &addrlen))
1041+
{
1042+
// Unable to get local socket address so use default...
1043+
DEBUG_printf(("4_httpTLSStart: Unable to get socket address: %s", strerror(errno)));
1044+
hostname[0] = '\0';
1045+
}
1046+
else if (httpAddrLocalhost(&addr))
1047+
{
1048+
// Local access top use default...
1049+
hostname[0] = '\0';
1050+
}
1051+
else
1052+
{
1053+
// Lookup the socket address...
1054+
httpAddrLookup(&addr, hostname, sizeof(hostname));
1055+
DEBUG_printf(("4_httpTLSStart: Resolved socket address to \"%s\".", hostname));
1056+
}
10501057
}
1051-
}
10521058

1053-
if (isdigit(hostname[0] & 255) || hostname[0] == '[')
1054-
hostname[0] = '\0'; // Don't allow numeric addresses
1059+
if (isdigit(hostname[0] & 255) || hostname[0] == '[')
1060+
hostname[0] = '\0'; // Don't allow numeric addresses
10551061

1056-
if (hostname[0])
1057-
cn = hostname;
1058-
else
1059-
cn = tls_common_name;
1062+
if (hostname[0])
1063+
cn = hostname;
10601064

1061-
_cupsMutexLock(&tls_mutex);
1065+
_cupsMutexLock(&tls_mutex);
1066+
}
1067+
1068+
if (!cn)
1069+
cn = tls_common_name;
10621070

10631071
if (cn)
10641072
{

0 commit comments

Comments
 (0)