Skip to content

Commit 0524a86

Browse files
committed
Clean up some Coverity-reported issues.
1 parent 302ceda commit 0524a86

5 files changed

Lines changed: 29 additions & 7 deletions

File tree

cups/file.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,17 +880,24 @@ cupsFilePrintf(cups_file_t *fp, // I - CUPS file
880880
va_start(ap, format);
881881
va_copy(ap2, ap);
882882
bytes = vsnprintf(fp->printf_buffer, fp->printf_size, format, ap2);
883+
va_end(ap2);
883884

884885
if (bytes >= (ssize_t)fp->printf_size)
885886
{
886887
// Expand the printf buffer...
887888
char *temp; // Temporary buffer pointer
888889

889890
if (bytes > 65535)
891+
{
892+
va_end(ap);
890893
return (-1);
894+
}
891895

892896
if ((temp = realloc(fp->printf_buffer, (size_t)(bytes + 1))) == NULL)
897+
{
898+
va_end(ap);
893899
return (-1);
900+
}
894901

895902
fp->printf_buffer = temp;
896903
fp->printf_size = (size_t)(bytes + 1);

cups/ipp.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1613,7 +1613,8 @@ ippDateToTime(const ipp_uchar_t *date) // I - RFC 2579 date info
16131613
unixdate.tm_min = date[5];
16141614
unixdate.tm_sec = date[6];
16151615

1616-
t = mktime(&unixdate);
1616+
if ((t = mktime(&unixdate)) < 0)
1617+
return (0);
16171618

16181619
if (date[8] == '-')
16191620
t += date[9] * 3600 + date[10] * 60;

cups/jwt.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "cups-private.h"
1111
#include "jwt.h"
1212
#include "json-private.h"
13+
#include <assert.h>
1314
#ifdef HAVE_OPENSSL
1415
# include <openssl/ecdsa.h>
1516
# include <openssl/evp.h>
@@ -421,6 +422,7 @@ cupsJWTHasValidSignature(
421422

422423
#ifdef HAVE_OPENSSL
423424
hash_len = cupsHashData(cups_jwa_algorithms[jwt->sigalg], text, text_len, hash, sizeof(hash));
425+
assert(hash_len > 0);
424426

425427
if ((rsa = make_rsa(jwk)) != NULL)
426428
{
@@ -457,6 +459,7 @@ cupsJWTHasValidSignature(
457459

458460
#ifdef HAVE_OPENSSL
459461
hash_len = cupsHashData(cups_jwa_algorithms[jwt->sigalg], text, text_len, hash, sizeof(hash));
462+
assert(hash_len > 0);
460463

461464
if ((ec = make_ec_key(jwk, true)) != NULL)
462465
{
@@ -1758,6 +1761,8 @@ make_signature(cups_jwt_t *jwt, // I - JWT
17581761
if ((rsa = make_rsa(jwk)) != NULL)
17591762
{
17601763
hash_len = cupsHashData(cups_jwa_algorithms[alg], text, text_len, hash, sizeof(hash));
1764+
assert(hash_len > 0);
1765+
17611766
if (RSA_sign(nids[alg - CUPS_JWA_RS256], hash, hash_len, signature, &siglen, rsa) == 1)
17621767
{
17631768
*sigsize = siglen;
@@ -1805,6 +1810,8 @@ make_signature(cups_jwt_t *jwt, // I - JWT
18051810
if ((ec = make_ec_key(jwk, false)) != NULL)
18061811
{
18071812
hash_len = cupsHashData(cups_jwa_algorithms[alg], text, text_len, hash, sizeof(hash));
1813+
assert(hash_len > 0);
1814+
18081815
if ((ec_sig = ECDSA_do_sign(hash, hash_len, ec)) != NULL)
18091816
{
18101817
// Get the raw coordinates...

cups/langprintf.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// Localized printf/puts functions for CUPS.
33
//
4-
// Copyright © 2022 by OpenPrinting.
4+
// Copyright © 2022-2024 by OpenPrinting.
55
// Copyright © 2007-2014 by Apple Inc.
66
// Copyright © 2002-2007 by Easy Software Products.
77
//
@@ -110,6 +110,7 @@ cupsLangPuts(FILE *fp, // I - File to write to
110110
const char *message) // I - Message string to use
111111
{
112112
ssize_t bytes; // Number of bytes formatted
113+
size_t length = 0; // Total length
113114
char output[8192]; // Message buffer
114115
_cups_globals_t *cg = _cupsGlobals(); // Global data
115116

@@ -122,12 +123,14 @@ cupsLangPuts(FILE *fp, // I - File to write to
122123
cg->lang_default = cupsLangDefault();
123124

124125
// Transcode to the destination charset...
125-
bytes = cupsUTF8ToCharset(output, cupsLangGetString(cg->lang_default, message), sizeof(output) - 4, cg->lang_encoding);
126-
bytes += cupsUTF8ToCharset(output + bytes, "\n", sizeof(output) - (size_t)bytes, cg->lang_encoding);
126+
if ((bytes = cupsUTF8ToCharset(output, cupsLangGetString(cg->lang_default, message), sizeof(output) - 4, cg->lang_encoding)) > 0)
127+
length += (size_t)bytes;
128+
if ((bytes = cupsUTF8ToCharset(output + length, "\n", sizeof(output) - length, cg->lang_encoding)) > 0)
129+
length += (size_t)bytes;
127130

128131
// Write the string and return the number of bytes written...
129-
if (bytes > 0)
130-
return ((ssize_t)fwrite(output, 1, (size_t)bytes, fp));
132+
if (length > 0)
133+
return ((ssize_t)fwrite(output, 1, length, fp));
131134
else
132135
return (bytes);
133136
}

cups/oauth.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1348,8 +1348,12 @@ oauth_copy_response(http_t *http) // I - HTTP connection
13481348
// Allocate memory for string...
13491349
initial_state = httpGetState(http);
13501350

1351-
if ((bodylen = (size_t)httpGetLength(http)) == 0 || bodylen > 65536)
1351+
if ((bytes = httpGetLength(http)) < 0)
1352+
return (NULL);
1353+
else if (bytes == 0 || bytes > 65536)
13521354
bodylen = 65536; // Accept up to 64k for GETs/POSTs
1355+
else
1356+
bodylen = (size_t)bytes;
13531357

13541358
if ((body = calloc(1, bodylen + 1)) != NULL)
13551359
{

0 commit comments

Comments
 (0)