Skip to content

Commit 0ac8153

Browse files
committed
Fix some Coverity-detected issues.
1 parent 5607643 commit 0ac8153

File tree

5 files changed

+18
-9
lines changed

5 files changed

+18
-9
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ libcups v3.0.0 (YYYY-MM-DD)
1111
- Fixed a potential timing issue with `cupsEnumDests`.
1212
- Fixed a bug in the Avahi implementation of `cupsDNSSDBrowseNew`.
1313
- Fixed a memory leak in `httpClose`.
14+
- Fixed some Coverity-detected issues.
1415

1516

1617
libcups v3.0rc4 (2025-03-18)

cups/dnssd.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3009,20 +3009,19 @@ avahi_resolve_cb(
30093009

30103010
DEBUG_printf("3avahi_resolve_cb(resolver=%p, if_index=%d, protocol=%d, event=%s, name=\"%s\", type=\"%s\", domain=\"%s\", host=\"%s\", address=%p, port=%u, txtrec=%p, flags=%u, resolve=%p)", (void *)resolver, if_index, protocol, avahi_events[event], name, type, domain, host, (void *)address, (unsigned)port, (void *)txtrec, (unsigned)flags, (void *)resolve);
30113011

3012-
if (!resolver || event != AVAHI_RESOLVER_FOUND)
3012+
if (!resolver)
30133013
return;
30143014

3015-
(void)resolver;
30163015
(void)protocol;
30173016
(void)flags;
30183017

30193018
// Map the addresses "127.0.0.1" (IPv4) and "::1" (IPv6) to "localhost" to work around a well-known Avahi registration bug for local-only services (Issue #970)
3020-
if (address->proto == AVAHI_PROTO_INET && address->data.ipv4.address == htonl(0x7f000001))
3019+
if (address && address->proto == AVAHI_PROTO_INET && address->data.ipv4.address == htonl(0x7f000001))
30213020
{
30223021
DEBUG_puts("4avahi_resolve_cb: Mapping 127.0.0.1 to localhost.");
30233022
host = "localhost";
30243023
}
3025-
else if (address->proto == AVAHI_PROTO_INET6 && address->data.ipv6.address[0] == 0 && address->data.ipv6.address[1] == 0 && address->data.ipv6.address[2] == 0 && address->data.ipv6.address[3] == 0 && address->data.ipv6.address[4] == 0 && address->data.ipv6.address[5] == 0 && address->data.ipv6.address[6] == 0 && address->data.ipv6.address[7] == 0 && address->data.ipv6.address[8] == 0 && address->data.ipv6.address[9] == 0 && address->data.ipv6.address[10] == 0 && address->data.ipv6.address[11] == 0 && address->data.ipv6.address[12] == 0 && address->data.ipv6.address[13] == 0 && address->data.ipv6.address[14] == 0 && address->data.ipv6.address[15] == 1)
3024+
else if (address && address->proto == AVAHI_PROTO_INET6 && address->data.ipv6.address[0] == 0 && address->data.ipv6.address[1] == 0 && address->data.ipv6.address[2] == 0 && address->data.ipv6.address[3] == 0 && address->data.ipv6.address[4] == 0 && address->data.ipv6.address[5] == 0 && address->data.ipv6.address[6] == 0 && address->data.ipv6.address[7] == 0 && address->data.ipv6.address[8] == 0 && address->data.ipv6.address[9] == 0 && address->data.ipv6.address[10] == 0 && address->data.ipv6.address[11] == 0 && address->data.ipv6.address[12] == 0 && address->data.ipv6.address[13] == 0 && address->data.ipv6.address[14] == 0 && address->data.ipv6.address[15] == 1)
30263025
{
30273026
DEBUG_puts("4avahi_resolve_cb: Mapping ::1 to localhost.");
30283027
host = "localhost";

cups/http.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,6 +1562,7 @@ httpPeek(http_t *http, // I - HTTP connection
15621562
{
15631563
DEBUG_puts("2httpPeek: Unable to copy decompressor stream.");
15641564
http->error = ENOMEM;
1565+
inflateEnd(&stream);
15651566
return (-1);
15661567
}
15671568

cups/tls-gnutls.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1740,8 +1740,12 @@ _httpTLSStart(http_t *http) // I - Connection to server
17401740
*cnptr; // Pointer into common name
17411741
bool have_creds = false; // Have credentials?
17421742

1743+
cupsMutexLock(&tls_mutex);
1744+
17431745
if (!tls_common_name)
17441746
{
1747+
cupsMutexUnlock(&tls_mutex);
1748+
17451749
if (http->fields[HTTP_FIELD_HOST])
17461750
{
17471751
// Use hostname for TLS upgrade...
@@ -1775,9 +1779,9 @@ _httpTLSStart(http_t *http) // I - Connection to server
17751779

17761780
if (hostname[0])
17771781
cn = hostname;
1778-
}
17791782

1780-
cupsMutexLock(&tls_mutex);
1783+
cupsMutexLock(&tls_mutex);
1784+
}
17811785

17821786
if (!cn)
17831787
cn = tls_common_name;

cups/tls-openssl.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1797,9 +1797,13 @@ _httpTLSStart(http_t *http) // I - Connection to server
17971797

17981798
context = SSL_CTX_new(TLS_server_method());
17991799

1800+
// Find the TLS certificate...
1801+
cupsMutexLock(&tls_mutex);
1802+
18001803
if (!tls_common_name)
18011804
{
1802-
// Find the TLS certificate...
1805+
cupsMutexUnlock(&tls_mutex);
1806+
18031807
if (http->fields[HTTP_FIELD_HOST])
18041808
{
18051809
// Use hostname for TLS upgrade...
@@ -1836,9 +1840,9 @@ _httpTLSStart(http_t *http) // I - Connection to server
18361840

18371841
if (hostname[0])
18381842
cn = hostname;
1839-
}
18401843

1841-
cupsMutexLock(&tls_mutex);
1844+
cupsMutexLock(&tls_mutex);
1845+
}
18421846

18431847
if (!cn)
18441848
cn = tls_common_name;

0 commit comments

Comments
 (0)