Skip to content

Commit d7088f5

Browse files
committed
Fix coverity-detected issues.
1 parent 9057596 commit d7088f5

10 files changed

Lines changed: 796 additions & 13 deletions

File tree

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
@@ -1886,6 +1886,7 @@ httpPeek(http_t *http, // I - HTTP connection
18861886
{
18871887
DEBUG_puts("2httpPeek: Unable to copy decompressor stream.");
18881888
http->error = ENOMEM;
1889+
inflateEnd(&stream);
18891890
return (-1);
18901891
}
18911892

cups/tls-gnutls.c

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

1745+
cupsMutexLock(&tls_mutex);
1746+
17451747
if (!tls_common_name)
17461748
{
1749+
cupsMutexUnlock(&tls_mutex);
1750+
17471751
if (http->fields[HTTP_FIELD_HOST])
17481752
{
17491753
// Use hostname for TLS upgrade...
@@ -1777,9 +1781,9 @@ _httpTLSStart(http_t *http) // I - Connection to server
17771781

17781782
if (hostname[0])
17791783
cn = hostname;
1780-
}
17811784

1782-
cupsMutexLock(&tls_mutex);
1785+
cupsMutexLock(&tls_mutex);
1786+
}
17831787

17841788
if (!cn)
17851789
cn = tls_common_name;

cups/tls-openssl.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1715,8 +1715,12 @@ _httpTLSStart(http_t *http) // I - Connection to server
17151715
context = SSL_CTX_new(TLS_server_method());
17161716

17171717
// Find the TLS certificate...
1718+
cupsMutexLock(&tls_mutex);
1719+
17181720
if (!tls_common_name)
17191721
{
1722+
cupsMutexUnlock(&tls_mutex);
1723+
17201724
if (http->fields[HTTP_FIELD_HOST])
17211725
{
17221726
// Use hostname for TLS upgrade...
@@ -1753,9 +1757,9 @@ _httpTLSStart(http_t *http) // I - Connection to server
17531757

17541758
if (hostname[0])
17551759
cn = hostname;
1756-
}
17571760

1758-
cupsMutexLock(&tls_mutex);
1761+
cupsMutexLock(&tls_mutex);
1762+
}
17591763

17601764
if (!cn)
17611765
cn = tls_common_name;

scheduler/ipp.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,13 @@ cupsdProcessIPPRequest(
138138
ipp_attribute_t *username; /* requesting-user-name attr */
139139
int sub_id; /* Subscription ID */
140140
int valid = 1; /* Valid request? */
141-
int minor; /* Minor version */
141+
int major, /* IPP major version */
142+
minor; /* IPP minor version */
142143

143144

144-
cupsdLogClient(con, CUPSD_LOG_DEBUG, "%s IPP/%d.%d request_id=%d", ippOpString(ippGetOperation(con->request)), ippGetVersion(con->request, &minor), minor, ippGetRequestId(con->request));
145+
major = ippGetVersion(con->request, &minor);
146+
147+
cupsdLogClient(con, CUPSD_LOG_DEBUG, "%s IPP/%d.%d request_id=%d", ippOpString(ippGetOperation(con->request)), major, minor, ippGetRequestId(con->request));
145148

146149
if (LogLevel >= CUPSD_LOG_DEBUG2)
147150
{

scheduler/job.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4674,6 +4674,7 @@ load_request_root(void)
46744674
*/
46754675

46764676
while ((dent = cupsDirRead(dir)) != NULL)
4677+
{
46774678
if (strlen(dent->filename) >= 6 && dent->filename[0] == 'c')
46784679
{
46794680
/*
@@ -4730,6 +4731,7 @@ load_request_root(void)
47304731
cupsdDeleteJob(job, CUPSD_JOB_FORCE);
47314732
}
47324733
}
4734+
}
47334735

47344736
cupsDirClose(dir);
47354737
}

tools/ippevepcl.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Generic HP PCL printer command for ippeveprinter/CUPS.
33
*
4-
* Copyright © 2020-2024 by OpenPrinting.
4+
* Copyright © 2020-2025 by OpenPrinting.
55
* Copyright © 2019 by Apple Inc.
66
*
77
* Licensed under Apache License v2.0. See the file "LICENSE" for more
@@ -508,7 +508,11 @@ raster_to_pcl(const char *filename) /* I - File to print (NULL for stdin) */
508508
break;
509509
}
510510

511-
line = malloc(header.cupsBytesPerLine);
511+
if ((line = malloc(header.cupsBytesPerLine)) == NULL)
512+
{
513+
fprintf(stderr, "ERROR: Unable to allocate %u bytes for line, aborting.\n", header.cupsBytesPerLine);
514+
break;
515+
}
512516

513517
pcl_start_page(&header, page);
514518
for (y = 0; y < header.cupsHeight; y ++)

tools/ippeveps.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1091,7 +1091,11 @@ raster_to_ps(const char *filename) /* I - Filename */
10911091
break;
10921092
}
10931093

1094-
line = malloc(header.cupsBytesPerLine);
1094+
if ((line = malloc(header.cupsBytesPerLine)) == NULL)
1095+
{
1096+
fprintf(stderr, "ERROR: Unable to allocate %u bytes for line, aborting.\n", header.cupsBytesPerLine);
1097+
break;
1098+
}
10951099

10961100
dsc_page(page);
10971101

0 commit comments

Comments
 (0)