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;
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 */
* 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);
}
// 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.
...) // 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
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
# 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
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
#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 */
int fd; /* File descriptor */
struct stat info; /* File information */
char buffer[512]; /* Data buffer */
- size_t i; /* Looping var */
+ size_t i; /* Looping var */
/*
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);
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 */
/*
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;
}
/*