]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Apply some minor changes suggested by Coverity.
authorMichael R Sweet <msweet@msweet.org>
Tue, 10 Sep 2024 15:42:43 +0000 (11:42 -0400)
committerMichael R Sweet <msweet@msweet.org>
Tue, 10 Sep 2024 15:42:43 +0000 (11:42 -0400)
cups/ipp.c
cups/langprintf.c
ppdc/ppdc-source.cxx
scheduler/file.c

index 752d177cd201bc5fe6caeac97c71d9ac0afe3540..fdfd21b1c4c589529efdd7f03b5130f7aaf2b169 100644 (file)
@@ -1636,7 +1636,8 @@ ippDateToTime(const ipp_uchar_t *date)    // I - RFC 2579 date info
   unixdate.tm_min  = date[5];
   unixdate.tm_sec  = date[6];
 
-  t = mktime(&unixdate);
+  if ((t = mktime(&unixdate)) < 0)
+    return (0);
 
   if (date[8] == '-')
     t += date[9] * 3600 + date[10] * 60;
index bacf474a17c8ed52d31131bfe7921d2982637724..ac36e1f9466cb4281aab94128f5aadfbaeaab4b0 100644 (file)
@@ -209,6 +209,7 @@ _cupsLangPuts(FILE       *fp,               /* I - File to write to */
               const char *message)     /* I - Message string to use */
 {
   ssize_t      bytes;                  /* Number of bytes formatted */
+  size_t       length;                 /* Formatted message length */
   char         output[8192];           /* Message buffer */
   _cups_globals_t *cg;                 /* Global data */
 
@@ -229,18 +230,22 @@ _cupsLangPuts(FILE       *fp,             /* I - File to write to */
   * Transcode to the destination charset...
   */
 
-  bytes = cupsUTF8ToCharset(output,
-                           (cups_utf8_t *)_cupsLangString(cg->lang_default,
-                                                          message),
-                           sizeof(output) - 4, cg->lang_default->encoding);
-  bytes += cupsUTF8ToCharset(output + bytes, (cups_utf8_t *)"\n", (int)(sizeof(output) - (size_t)bytes), cg->lang_default->encoding);
+  if ((bytes = cupsUTF8ToCharset(output, (cups_utf8_t *)_cupsLangString(cg->lang_default, message), sizeof(output) - 4, cg->lang_default->encoding)) < 0)
+    return (-1);
+
+  length = (size_t)bytes;
+
+  if ((bytes = cupsUTF8ToCharset(output + bytes, (cups_utf8_t *)"\n", (int)(sizeof(output) - (size_t)bytes), cg->lang_default->encoding)) < 0)
+    return (-1);
+
+  length += (size_t)bytes;
 
  /*
   * Write the string and return the number of bytes written...
   */
 
   if (bytes > 0)
-    return ((int)fwrite(output, 1, (size_t)bytes, fp));
+    return ((int)fwrite(output, 1, length, fp));
   else
     return ((int)bytes);
 }
index 70b9c73206e796a5a0835d6f7099acae10d4819e..d7edb9d48c6fd82703c10511b777344e8bb51f39 100644 (file)
@@ -2,8 +2,8 @@
 // Source class for the CUPS PPD Compiler.
 //
 // Copyright © 2020-2024 by OpenPrinting.
-// Copyright 2007-2018 by Apple Inc.
-// Copyright 2002-2007 by Easy Software Products.
+// Copyright © 2007-2018 by Apple Inc.
+// Copyright © 2002-2007 by Easy Software Products.
 //
 // Licensed under Apache License v2.0.  See the file "LICENSE" for more
 // information.
@@ -2166,7 +2166,8 @@ ppdcSource::quotef(cups_file_t *fp,       // I - File to write to
                   ...)                 // I - Additional args as needed
 {
   va_list      ap;                     // Pointer to additional arguments
-  int          bytes;                  // Bytes written
+  int          bytes,                  // Bytes written
+               tbytes;                 // Temporary bytes written
   char         sign,                   // Sign of format width
                size,                   // Size character (h, l, L)
                type;                   // Format type character
@@ -2249,7 +2250,8 @@ ppdcSource::quotef(cups_file_t *fp,       // I - File to write to
            memcpy(tformat, bufformat, (size_t)(format - bufformat));
            tformat[format - bufformat] = '\0';
 
-           bytes += cupsFilePrintf(fp, tformat, va_arg(ap, double));
+           if ((tbytes = cupsFilePrintf(fp, tformat, va_arg(ap, double))) > 0)
+             bytes += tbytes;
            break;
 
         case 'B' : // Integer formats
@@ -2268,13 +2270,16 @@ ppdcSource::quotef(cups_file_t *fp,     // I - File to write to
 
 #  ifdef HAVE_LONG_LONG
             if (size == 'L')
-             bytes += cupsFilePrintf(fp, tformat, va_arg(ap, long long));
+             tbytes = cupsFilePrintf(fp, tformat, va_arg(ap, long long));
            else
 #  endif /* HAVE_LONG_LONG */
             if (size == 'l')
-             bytes += cupsFilePrintf(fp, tformat, va_arg(ap, long));
+             tbytes = cupsFilePrintf(fp, tformat, va_arg(ap, long));
            else
-             bytes += cupsFilePrintf(fp, tformat, va_arg(ap, int));
+             tbytes = cupsFilePrintf(fp, tformat, va_arg(ap, int));
+
+           if (tbytes > 0)
+             bytes += tbytes;
            break;
 
        case 'p' : // Pointer value
@@ -2284,7 +2289,8 @@ ppdcSource::quotef(cups_file_t *fp,       // I - File to write to
            memcpy(tformat, bufformat, (size_t)(format - bufformat));
            tformat[format - bufformat] = '\0';
 
-           bytes += cupsFilePrintf(fp, tformat, va_arg(ap, void *));
+           if ((tbytes = cupsFilePrintf(fp, tformat, va_arg(ap, void *))) > 0)
+             bytes += tbytes;
            break;
 
         case 'c' : // Character or character array
index e0a5a4540197393270d6f12d97cf7767bad0bb27..62c384383939b2c22da8d5746a6e3fdae9ad1bdf 100644 (file)
@@ -19,8 +19,7 @@
 #ifdef HAVE_REMOVEFILE
 #  include <removefile.h>
 #else
-static int     overwrite_data(int fd, const char *buffer, int bufsize,
-                              int filesize);
+static int     overwrite_data(int fd, const char *buffer, size_t bufsize, off_t filesize);
 #endif /* HAVE_REMOVEFILE */
 
 
@@ -316,7 +315,7 @@ cupsdRemoveFile(const char *filename)       /* I - File to remove */
   int                  fd;             /* File descriptor */
   struct stat          info;           /* File information */
   char                 buffer[512];    /* Data buffer */
-  size_t                       i;              /* Looping var */
+  size_t               i;              /* Looping var */
 
 
  /*
@@ -363,8 +362,8 @@ cupsdRemoveFile(const char *filename)       /* I - File to remove */
   CUPS_SRAND(time(NULL));
 
   for (i = 0; i < sizeof(buffer); i ++)
-    buffer[i] = CUPS_RAND();
-  if (overwrite_data(fd, buffer, sizeof(buffer), (int)info.st_size))
+    buffer[i] = (char)CUPS_RAND();
+  if (overwrite_data(fd, buffer, sizeof(buffer), info.st_size))
   {
     close(fd);
     return (-1);
@@ -403,10 +402,11 @@ cupsdUnlinkOrRemoveFile(
 static int                             /* O - 0 on success, -1 on error */
 overwrite_data(int        fd,          /* I - File descriptor */
                const char *buffer,     /* I - Buffer to write */
-              int        bufsize,      /* I - Size of buffer */
-               int        filesize)    /* I - Size of file */
+              size_t     bufsize,      /* I - Size of buffer */
+               off_t      filesize)    /* I - Size of file */
 {
-  int  bytes;                          /* Bytes to write/written */
+  size_t       wbytes;                 /* Bytes to write */
+  ssize_t      written;                /* Bytes written */
 
 
  /*
@@ -422,15 +422,18 @@ overwrite_data(int        fd,             /* I - File descriptor */
 
   while (filesize > 0)
   {
-    if (filesize > bufsize)
-      bytes = bufsize;
+    if (filesize > (off_t)bufsize)
+      wbytes = bufsize;
     else
-      bytes = filesize;
+      wbytes = (size_t)filesize;
 
-    if ((bytes = write(fd, buffer, (size_t)bytes)) < 0)
+    if ((written = write(fd, buffer, wbytes)) < 0)
       return (-1);
 
-    filesize -= bytes;
+    if ((off_t)written > filesize)
+      filesize = 0;
+    else
+      filesize -= (off_t)written;
   }
 
  /*