/*
* SNMP discovery backend for CUPS.
*
+ * Copyright © 2021 by OpenPrinting.
* Copyright © 2007-2014 by Apple Inc.
* Copyright © 2006-2007 by Easy Software Products, all rights reserved.
*
addr, addrname, uri ? uri : "(null)", id ? id : "(null)",
make_and_model ? make_and_model : "(null)");
- temp = calloc(1, sizeof(snmp_cache_t));
+ if ((temp = calloc(1, sizeof(snmp_cache_t))) == NULL)
+ {
+ perror("DEBUG: Unable to allocate cache entry");
+ return;
+ }
+
memcpy(&(temp->address), addr, sizeof(temp->address));
temp->addrname = strdup(addrname);
* our own file functions allows us to provide transparent support of
* different line endings, gzip'd print files, PPD files, etc.
*
+ * Copyright © 2021 by OpenPrinting.
* Copyright © 2007-2019 by Apple Inc.
* Copyright © 1997-2007 by Easy Software Products, all rights reserved.
*
*/
struct _cups_file_s /**** CUPS file structure... ****/
-
{
int fd; /* File descriptor */
char mode, /* Mode ('r' or 'w') */
* Initialize the compressor...
*/
- deflateInit2(&(fp->stream), mode[1] - '0', Z_DEFLATED, -15, 8,
- Z_DEFAULT_STRATEGY);
+ if (deflateInit2(&(fp->stream), mode[1] - '0', Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY) < Z_OK)
+ {
+ close(fd);
+ free(fp);
+ return (NULL);
+ }
fp->stream.next_out = fp->cbuf;
fp->stream.avail_out = sizeof(fp->cbuf);
*/
DEBUG_printf(("cupsFileRewind(fp=%p)", (void *)fp));
- DEBUG_printf(("2cupsFileRewind: pos=" CUPS_LLFMT, CUPS_LLCAST fp->pos));
if (!fp || fp->mode != 'r')
return (-1);
+ DEBUG_printf(("2cupsFileRewind: pos=" CUPS_LLFMT, CUPS_LLCAST fp->pos));
+
/*
* Handle special cases...
*/
DEBUG_printf(("cupsFileSeek(fp=%p, pos=" CUPS_LLFMT ")", (void *)fp, CUPS_LLCAST pos));
- DEBUG_printf(("2cupsFileSeek: fp->pos=" CUPS_LLFMT, CUPS_LLCAST fp->pos));
- DEBUG_printf(("2cupsFileSeek: fp->ptr=%p, fp->end=%p", (void *)fp->ptr, (void *)fp->end));
/*
* Range check input...
if (!fp || pos < 0 || fp->mode != 'r')
return (-1);
+ DEBUG_printf(("2cupsFileSeek: fp->pos=" CUPS_LLFMT, CUPS_LLCAST fp->pos));
+ DEBUG_printf(("2cupsFileSeek: fp->ptr=%p, fp->end=%p", (void *)fp->ptr, (void *)fp->end));
+
/*
* Handle special cases...
*/
const char *buf, /* I - Buffer */
size_t bytes) /* I - Number bytes */
{
+ int status; /* Deflate status */
+
+
DEBUG_printf(("7cups_compress(fp=%p, buf=%p, bytes=" CUPS_LLFMT ")", (void *)fp, (void *)buf, CUPS_LLCAST bytes));
/*
fp->stream.avail_out = sizeof(fp->cbuf);
}
- deflate(&(fp->stream), Z_NO_FLUSH);
+ if ((status = deflate(&(fp->stream), Z_NO_FLUSH)) < Z_OK && status != Z_BUF_ERROR)
+ return (-1);
}
return ((ssize_t)bytes);
off_t remaining; /* Remaining length */
- DEBUG_printf(("2httpGetLength2(http=%p), state=%s", (void *)http, httpStateString(http->state)));
+ DEBUG_printf(("2httpGetLength2(http=%p), state=%s", (void *)http, http ? httpStateString(http->state) : "NONE"));
if (!http)
return (-1);
#ifdef HAVE_LIBZ
- DEBUG_printf(("httpRead2(http=%p, buffer=%p, length=" CUPS_LLFMT ") coding=%d data_encoding=%d data_remaining=" CUPS_LLFMT, (void *)http, (void *)buffer, CUPS_LLCAST length, http->coding, http->data_encoding, CUPS_LLCAST http->data_remaining));
+ DEBUG_printf(("httpRead2(http=%p, buffer=%p, length=" CUPS_LLFMT ") coding=%d data_encoding=%d data_remaining=" CUPS_LLFMT, (void *)http, (void *)buffer, CUPS_LLCAST length, http ? http->coding : 0, http ? http->data_encoding : 0, CUPS_LLCAST (http ? http->data_remaining : -1)));
#else
- DEBUG_printf(("httpRead2(http=%p, buffer=%p, length=" CUPS_LLFMT ") data_encoding=%d data_remaining=" CUPS_LLFMT, (void *)http, (void *)buffer, CUPS_LLCAST length, http->data_encoding, CUPS_LLCAST http->data_remaining));
+ DEBUG_printf(("httpRead2(http=%p, buffer=%p, length=" CUPS_LLFMT ") data_encoding=%d data_remaining=" CUPS_LLFMT, (void *)http, (void *)buffer, CUPS_LLCAST length, http ? http->data_encoding : 0, CUPS_LLCAST (http ? http->data_remaining : -1)));
#endif /* HAVE_LIBZ */
if (http == NULL || buffer == NULL)
const char *value, /* I - Value string */
int append) /* I - Append value? */
{
- char temp[1024]; /* Temporary value string */
+ char temp[1024], /* Temporary value string */
+ combined[HTTP_MAX_VALUE];
+ /* Combined value string */
size_t fieldlen, /* Length of existing value */
valuelen, /* Length of value string */
total; /* Total length of string */
if (fieldlen)
{
- char combined[HTTP_MAX_VALUE];
- /* Combined value string */
-
snprintf(combined, sizeof(combined), "%s, %s", http->_fields[field], value);
value = combined;
}
* Expand the field value...
*/
- char *combined; /* New value string */
+ char *mcombined; /* New value string */
if (http->fields[field] == http->_fields[field])
{
- if ((combined = malloc(total + 1)) != NULL)
+ if ((mcombined = malloc(total + 1)) != NULL)
{
- http->fields[field] = combined;
- snprintf(combined, total + 1, "%s, %s", http->_fields[field], value);
+ http->fields[field] = mcombined;
+ snprintf(mcombined, total + 1, "%s, %s", http->_fields[field], value);
}
}
- else if ((combined = realloc(http->fields[field], total + 1)) != NULL)
+ else if ((mcombined = realloc(http->fields[field], total + 1)) != NULL)
{
- http->fields[field] = combined;
- strlcat(combined, ", ", total + 1);
- strlcat(combined, value, total + 1);
+ http->fields[field] = mcombined;
+ strlcat(mcombined, ", ", total + 1);
+ strlcat(mcombined, value, total + 1);
}
}
else
#ifdef DEBUG
if (bytes > 0)
http_debug_hex("http_read", buffer, (int)bytes);
+ else
#endif /* DEBUG */
-
- if (bytes < 0)
- {
-#ifdef _WIN32
- if (WSAGetLastError() == WSAEINTR)
- bytes = 0;
- else
- http->error = WSAGetLastError();
-#else
- if (errno == EINTR || (errno == EAGAIN && !http->timeout_cb))
- bytes = 0;
- else
- http->error = errno;
-#endif /* _WIN32 */
- }
- else if (bytes == 0)
+ if (bytes == 0)
{
http->error = EPIPE;
return (0);
value = cupsGetOption("com.apple.print.PrintSettings.PMTotalBeginPages..n.", num_options, options);
if (value)
- job_pages = atoi(value);
+ {
+ if ((job_pages = atoi(value)) < 1)
+ job_pages = 1;
+ }
// Adjust for number-up
if ((value = cupsGetOption("number-up", num_options, options)) != NULL)
- number_up = atoi(value);
+ {
+ if ((number_up = atoi(value)) < 1)
+ number_up = 1;
+ }
job_pages = (job_pages + number_up - 1) / number_up;
{
if (con->file >= 0)
{
- fstat(con->file, &filestats);
+ if (fstat(con->file, &filestats))
+ filestats.st_size = 0;
close(con->file);
con->file = -1;
/*
* Color management routines for the CUPS scheduler.
*
- * Copyright 2007-2014 by Apple Inc.
- * Copyright 1997-2007 by Easy Software Products, all rights reserved.
+ * Copyright © 2021 by OpenPrinting.
+ * Copyright © 2007-2014 by Apple Inc.
+ * Copyright © 1997-2007 by Easy Software Products, all rights reserved.
*
- * Licensed under Apache License v2.0. See the file "LICENSE" for more information.
+ * Licensed under Apache License v2.0. See the file "LICENSE" for more
+ * information.
*
- * Original DBUS/colord code is Copyright 2011 Red Hat, Inc.
+ * Original DBUS/colord code is Copyright © 2011 Red Hat, Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
DBusError error; /* D-Bus error */
const char *device_path; /* Device object path */
const char *profile_path; /* Profile path */
- char *default_profile_path = NULL;
- /* Default profile path */
char device_id[1024]; /* Device ID as understood by colord */
char format_str[1024]; /* Qualifier format as a string */
colord_device_add_profile(device_path, profile_path, relation);
}
-out:
-
- if (default_profile_path)
- free(default_profile_path);
+ out:
if (message)
dbus_message_unref(message);
* created from driver information files, and dynamically generated PPD files
* using driver helper programs.
*
+ * Copyright © 2021 by OpenPrinting.
* Copyright © 2007-2019 by Apple Inc.
* Copyright © 1997-2007 by Easy Software Products.
*
}
if (cupsFileTell(fp) != next)
- cupsFileSeek(fp, next);
+ {
+ if (cupsFileSeek(fp, next) != next)
+ break;
+ }
}
cupsFileClose(fp);
/*
* Line Printer Daemon interface for CUPS.
*
- * Copyright 2007-2016 by Apple Inc.
- * Copyright 1997-2006 by Easy Software Products, all rights reserved.
+ * Copyright © 2021 by OpenPrinting.
+ * Copyright © 2007-2016 by Apple Inc.
+ * Copyright © 1997-2006 by Easy Software Products, all rights reserved.
*
- * Licensed under Apache License v2.0. See the file "LICENSE" for more information.
+ * Licensed under Apache License v2.0. See the file "LICENSE" for more
+ * information.
*/
/*
&options);
break;
}
-
- if (status)
- break;
}
/*
snprintf(buffer, sizeof(buffer), "%s/daemon/cups-driverd", ServerBin);
snprintf(tempfile, sizeof(tempfile), "%s/%d.ppd", TempDir, con->number);
- tempfd = open(tempfile, O_WRONLY | O_CREAT | O_TRUNC, 0600);
- if (tempfd < 0 || cupsdOpenPipe(temppipe))
+ if ((tempfd = open(tempfile, O_WRONLY | O_CREAT | O_TRUNC, 0600)) < 0)
return (-1);
+ if (cupsdOpenPipe(temppipe))
+ {
+ close(tempfd);
+ unlink(tempfile);
+
+ return (-1);
+ }
cupsdLogMessage(CUPSD_LOG_DEBUG,
"copy_model: Running \"cups-driverd cat %s\"...", from);
/* Status code */
_cupsLangPrintf(stderr, _("lpadmin: Unable to open PPD \"%s\": %s on line %d."), ppdfile, ppdErrorString(status), linenum);
- return (1);
+ goto error;
}
ppdMarkDefaults(ppd);
if ((out = cupsTempFile2(tempfile, sizeof(tempfile))) == NULL)
{
_cupsLangPrintError(NULL, _("lpadmin: Unable to create temporary file"));
- ippDelete(request);
- if (ppdfile != file)
- unlink(ppdfile);
- if (copied_options)
- cupsFreeOptions(num_options, options);
- return (1);
+ goto error;
}
if ((in = cupsFileOpen(ppdfile, "r")) == NULL)
{
_cupsLangPrintf(stderr, _("lpadmin: Unable to open PPD \"%s\": %s"), ppdfile, strerror(errno));
- ippDelete(request);
- if (ppdfile != file)
- unlink(ppdfile);
- if (copied_options)
- cupsFreeOptions(num_options, options);
cupsFileClose(out);
unlink(tempfile);
- return (1);
+ goto error;
}
while (cupsFileGets(in, line, sizeof(line)))
}
else
return (0);
+
+ /*
+ * Error handling...
+ */
+
+ error:
+
+ ippDelete(request);
+
+ if (ppdfile != file)
+ unlink(ppdfile);
+
+ if (copied_options)
+ cupsFreeOptions(num_options, options);
+
+ return (1);
}
if ((job = calloc(1, sizeof(ippeve_job_t))) == NULL)
{
perror("Unable to allocate memory for job");
+ _cupsRWUnlock(&(client->printer->rwlock));
return (NULL);
}
/*
* Generic Adobe PostScript printer command for ippeveprinter/CUPS.
*
+ * Copyright © 2021 by OpenPrinting.
* Copyright © 2019 by Apple Inc.
*
* Licensed under Apache License v2.0. See the file "LICENSE" for more
int copy_page = 0; /* Do we copy the page data? */
if (fp != stdin)
- fseek(fp, first_pos, SEEK_SET);
+ {
+ if (fseek(fp, first_pos, SEEK_SET) < 0)
+ {
+ perror("ERROR: Unable to seek within PostScript file");
+ break;
+ }
+ }
page = 0;
while (fgets(line, sizeof(line), fp))