* Yes, add the device...
*/
- device = calloc(sizeof(cups_device_t), 1);
+ if ((device = calloc(sizeof(cups_device_t), 1)) == NULL)
+ {
+ perror("DEBUG: Out of memory adding a device");
+ return (NULL);
+ }
+
device->name = strdup(serviceName);
device->domain = strdup(replyDomain);
device->type = key.type;
return (NULL);
for (addr = addrs, first = NULL, last = NULL; addr; addr = addr->ifa_next)
+ {
if ((addr->ifa_flags & IFF_BROADCAST) && addr->ifa_broadaddr &&
addr->ifa_broadaddr->sa_family == AF_INET &&
(!ifname || !strcmp(ifname, addr->ifa_name)))
{
- current = calloc(1, sizeof(http_addrlist_t));
-
- memcpy(&(current->addr), addr->ifa_broadaddr,
- sizeof(struct sockaddr_in));
+ if ((current = calloc(1, sizeof(http_addrlist_t))) != NULL)
+ {
+ memcpy(&(current->addr), addr->ifa_broadaddr,
+ sizeof(struct sockaddr_in));
- if (!last)
- first = current;
- else
- last->next = current;
+ if (!last)
+ first = current;
+ else
+ last->next = current;
- last = current;
+ last = current;
+ }
}
+ }
freeifaddrs(addrs);
)
remote_access = 1;
}
- else if (!_cups_strcasecmp(line, "Browsing"))
+ else if (!_cups_strcasecmp(line, "Browsing") && value)
{
browsing = !_cups_strcasecmp(value, "yes") ||
!_cups_strcasecmp(value, "on") ||
!_cups_strcasecmp(value, "true");
}
- else if (!_cups_strcasecmp(line, "LogLevel"))
+ else if (!_cups_strcasecmp(line, "LogLevel") && value)
{
debug_logging = !_cups_strncasecmp(value, "debug", 5);
}
- else if (!_cups_strcasecmp(line, "<Policy") &&
- !_cups_strcasecmp(value, "default"))
+ else if (!_cups_strcasecmp(line, "<Policy") && value && !_cups_strcasecmp(value, "default"))
{
in_policy = 1;
}
/*
* Destination option/media support for CUPS.
*
+ * Copyright © 2021 by OpenPrinting.
* Copyright © 2012-2019 by Apple Inc.
*
* Licensed under Apache License v2.0. See the file "LICENSE" for more
}
}
- if (best)
- {
- /*
- * Return the matching size...
- */
-
- if (best->key)
- strlcpy(size->media, best->key, sizeof(size->media));
- else if (best->size_name)
- strlcpy(size->media, best->size_name, sizeof(size->media));
- else if (pwg && pwg->pwg)
- strlcpy(size->media, pwg->pwg, sizeof(size->media));
- else
- strlcpy(size->media, "unknown", sizeof(size->media));
+ /*
+ * Return the matching size...
+ */
- size->width = best->width;
- size->length = best->length;
- size->bottom = best->bottom;
- size->left = best->left;
- size->right = best->right;
- size->top = best->top;
+ if (best->key)
+ strlcpy(size->media, best->key, sizeof(size->media));
+ else if (best->size_name)
+ strlcpy(size->media, best->size_name, sizeof(size->media));
+ else if (pwg->pwg)
+ strlcpy(size->media, pwg->pwg, sizeof(size->media));
+ else
+ strlcpy(size->media, "unknown", sizeof(size->media));
- return (1);
- }
+ size->width = best->width;
+ size->length = best->length;
+ size->bottom = best->bottom;
+ size->left = best->left;
+ size->right = best->right;
+ size->top = best->top;
- return (0);
+ return (1);
}
!strcmp(regtype, "_ipps._tcp") ? "IPPS" : "IPP",
replyDomain));
- device = calloc(sizeof(_cups_dnssd_device_t), 1);
- device->dest.name = _cupsStrAlloc(name);
- device->domain = _cupsStrAlloc(replyDomain);
- device->regtype = _cupsStrAlloc(regtype);
+ if ((device = calloc(sizeof(_cups_dnssd_device_t), 1)) != NULL)
+ {
+ device->dest.name = _cupsStrAlloc(name);
+ device->domain = _cupsStrAlloc(replyDomain);
+ device->regtype = _cupsStrAlloc(regtype);
- device->dest.num_options = cupsAddOption("printer-info", serviceName, 0, &device->dest.options);
+ device->dest.num_options = cupsAddOption("printer-info", serviceName, 0, &device->dest.options);
- cupsArrayAdd(data->devices, device);
+ cupsArrayAdd(data->devices, device);
+ }
}
/*
/*
* HTTP address list routines for CUPS.
*
+ * Copyright © 2021 by OpenPrinting.
* Copyright © 2007-2021 by Apple Inc.
* Copyright © 1997-2007 by Easy Software Products, all rights reserved.
*
http_addrlist_t *first, /* First address in list */
*addr, /* Current address in list */
*temp; /* New address */
+ char ipv6[64], /* IPv6 address */
+ *ipv6zone; /* Pointer to zone separator */
+ int ipv6len; /* Length of IPv6 address */
_cups_globals_t *cg = _cupsGlobals();
/* Global data */
struct addrinfo hints, /* Address lookup hints */
*results, /* Address lookup results */
*current; /* Current result */
- char ipv6[64], /* IPv6 address */
- *ipv6zone; /* Pointer to zone separator */
- int ipv6len; /* Length of IPv6 address */
int error; /* getaddrinfo() error */
* Figure out the scheme from the full name...
*/
- if (strstr(type, "_ipp."))
- scheme = "ipp";
- else if (strstr(type, "_printer."))
- scheme = "lpd";
- else if (strstr(type, "_pdl-datastream."))
- scheme = "socket";
- else
- scheme = "riousbprint";
-
if (!strncmp(type, "_ipps.", 6) || !strncmp(type, "_ipp-tls.", 9))
scheme = "ipps";
else if (!strncmp(type, "_ipp.", 5) || !strncmp(type, "_fax-ipp.", 9))
if (!valuelen)
{
- http->_fields[field][0] = '\0';
+ if (field < HTTP_FIELD_ACCEPT_ENCODING)
+ http->_fields[field][0] = '\0';
return;
}
/*
* Threading primitives for CUPS.
*
+ * Copyright © 2021 by OpenPrinting.
* Copyright © 2009-2018 by Apple Inc.
*
* Licensed under Apache License v2.0. See the file "LICENSE" for more
abstime.tv_sec ++;
};
- pthread_cond_timedwait(cond, mutex, &abstime);
+ (void)pthread_cond_timedwait(cond, mutex, &abstime);
}
else
- pthread_cond_wait(cond, mutex);
+ (void)pthread_cond_wait(cond, mutex);
}
/*
* GZIP/raw pre-filter for CUPS.
*
- * Copyright 2007-2015 by Apple Inc.
- * Copyright 1993-2007 by Easy Software Products.
+ * Copyright © 2021 by OpenPrinting.
+ * Copyright © 2007-2015 by Apple Inc.
+ * Copyright © 1993-2007 by Easy Software Products.
*
- * 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.
*/
/*
*/
if (!getenv("FINAL_CONTENT_TYPE"))
- copies = atoi(argv[4]);
+ {
+ if ((copies = atoi(argv[4])) < 1)
+ copies = 1;
+ }
else
+ {
copies = 1;
+ }
/*
* Open the file...
break;
case 0x05 : /* Remove jobs */
- if (list)
- {
- /*
- * Grab the agent and skip to the list of users and/or jobs.
- */
+ /*
+ * Grab the agent and skip to the list of users and/or jobs.
+ */
- agent = list;
+ agent = list;
- for (; *list && !isspace(*list & 255); list ++);
- while (isspace(*list & 255))
- *list++ = '\0';
+ for (; *list && !isspace(*list & 255); list ++);
+ while (isspace(*list & 255))
+ *list++ = '\0';
- syslog(LOG_INFO, "Remove jobs %s on %s by %s", list, dest, agent);
+ syslog(LOG_INFO, "Remove jobs %s on %s by %s", list, dest, agent);
- status = (char)remove_jobs(dest, agent, list);
- }
- else
- status = 1;
+ status = (char)remove_jobs(dest, agent, list);
putchar(status);
break;
{
send_ipp_status(con, IPP_NOT_FOUND, _("Job #%d does not exist."),
job_ids->values[i].integer);
+ cupsArrayDelete(ra);
return;
}
/*
* Log file routines for the CUPS scheduler.
*
+ * Copyright © 2021 by OpenPrinting.
* Copyright © 2007-2018 by Apple Inc.
* Copyright © 1997-2007 by Easy Software Products, all rights reserved.
*
{
pwg_media_t *pwg = pwgMediaForSize(ippGetInteger(x_dimension, 0), ippGetInteger(y_dimension, 0));
/* PWG media name */
- strlcpy(bufptr, pwg->pwg, sizeof(buffer) - (size_t)(bufptr - buffer));
- break;
+ if (pwg)
+ {
+ strlcpy(bufptr, pwg->pwg, sizeof(buffer) - (size_t)(bufptr - buffer));
+ break;
+ }
}
}
/*
* MIME typing routines for CUPS.
*
+ * Copyright © 2021 by OpenPrinting.
* Copyright © 2007-2019 by Apple Inc.
* Copyright © 1997-2006 by Easy Software Products, all rights reserved.
*
* Reload file buffer...
*/
- cupsFileSeek(fb->fp, rules->offset);
- fb->length = cupsFileRead(fb->fp, (char *)fb->buffer,
- sizeof(fb->buffer));
- fb->offset = rules->offset;
+ if (cupsFileSeek(fb->fp, rules->offset) < 0)
+ {
+ fb->length = 0;
+ fb->offset = 0;
+ }
+ else
+ {
+ fb->length = cupsFileRead(fb->fp, (char *)fb->buffer, sizeof(fb->buffer));
+ fb->offset = rules->offset;
+ }
DEBUG_printf(("4mime_check_rules: MIME_MAGIC_ASCII fb->length=%d", fb->length));
}
* Reload file buffer...
*/
- cupsFileSeek(fb->fp, rules->offset);
- fb->length = cupsFileRead(fb->fp, (char *)fb->buffer,
- sizeof(fb->buffer));
- fb->offset = rules->offset;
+ if (cupsFileSeek(fb->fp, rules->offset) < 0)
+ {
+ fb->length = 0;
+ fb->offset = 0;
+ }
+ else
+ {
+ fb->length = cupsFileRead(fb->fp, (char *)fb->buffer, sizeof(fb->buffer));
+ fb->offset = rules->offset;
+ }
DEBUG_printf(("4mime_check_rules: MIME_MAGIC_PRINTABLE fb->length=%d", fb->length));
}
* Reload file buffer...
*/
- cupsFileSeek(fb->fp, rules->offset);
- fb->length = cupsFileRead(fb->fp, (char *)fb->buffer,
- sizeof(fb->buffer));
- fb->offset = rules->offset;
+ if (cupsFileSeek(fb->fp, rules->offset) < 0)
+ {
+ fb->length = 0;
+ fb->offset = 0;
+ }
+ else
+ {
+ fb->length = cupsFileRead(fb->fp, (char *)fb->buffer, sizeof(fb->buffer));
+ fb->offset = rules->offset;
+ }
DEBUG_printf(("4mime_check_rules: MIME_MAGIC_REGEX fb->length=%d", fb->length));
* Reload file buffer...
*/
- cupsFileSeek(fb->fp, rules->offset);
- fb->length = cupsFileRead(fb->fp, (char *)fb->buffer,
- sizeof(fb->buffer));
- fb->offset = rules->offset;
+ if (cupsFileSeek(fb->fp, rules->offset) < 0)
+ {
+ fb->length = 0;
+ fb->offset = 0;
+ }
+ else
+ {
+ fb->length = cupsFileRead(fb->fp, (char *)fb->buffer, sizeof(fb->buffer));
+ fb->offset = rules->offset;
+ }
DEBUG_printf(("4mime_check_rules: MIME_MAGIC_STRING fb->length=%d", fb->length));
* Reload file buffer...
*/
- cupsFileSeek(fb->fp, rules->offset);
- fb->length = cupsFileRead(fb->fp, (char *)fb->buffer,
- sizeof(fb->buffer));
- fb->offset = rules->offset;
+ if (cupsFileSeek(fb->fp, rules->offset) < 0)
+ {
+ fb->length = 0;
+ fb->offset = 0;
+ }
+ else
+ {
+ fb->length = cupsFileRead(fb->fp, (char *)fb->buffer, sizeof(fb->buffer));
+ fb->offset = rules->offset;
+ }
DEBUG_printf(("4mime_check_rules: MIME_MAGIC_ISTRING fb->length=%d", fb->length));
}
* Reload file buffer...
*/
- cupsFileSeek(fb->fp, rules->offset);
- fb->length = cupsFileRead(fb->fp, (char *)fb->buffer,
- sizeof(fb->buffer));
- fb->offset = rules->offset;
+ if (cupsFileSeek(fb->fp, rules->offset) < 0)
+ {
+ fb->length = 0;
+ fb->offset = 0;
+ }
+ else
+ {
+ fb->length = cupsFileRead(fb->fp, (char *)fb->buffer, sizeof(fb->buffer));
+ fb->offset = rules->offset;
+ }
DEBUG_printf(("4mime_check_rules: MIME_MAGIC_CHAR fb->length=%d", fb->length));
}
if (fb->length < 1)
result = 0;
else
- result = (fb->buffer[rules->offset - fb->offset] ==
- rules->value.charv);
+ result = (fb->buffer[rules->offset - fb->offset] == rules->value.charv);
break;
case MIME_MAGIC_SHORT :
* Reload file buffer...
*/
- cupsFileSeek(fb->fp, rules->offset);
- fb->length = cupsFileRead(fb->fp, (char *)fb->buffer,
- sizeof(fb->buffer));
- fb->offset = rules->offset;
+ if (cupsFileSeek(fb->fp, rules->offset) < 0)
+ {
+ fb->length = 0;
+ fb->offset = 0;
+ }
+ else
+ {
+ fb->length = cupsFileRead(fb->fp, (char *)fb->buffer, sizeof(fb->buffer));
+ fb->offset = rules->offset;
+ }
DEBUG_printf(("4mime_check_rules: MIME_MAGIC_SHORT fb->length=%d", fb->length));
}
*/
if (fb->length < 2)
+ {
result = 0;
+ }
else
{
bufptr = fb->buffer + rules->offset - fb->offset;
* Reload file buffer...
*/
- cupsFileSeek(fb->fp, rules->offset);
- fb->length = cupsFileRead(fb->fp, (char *)fb->buffer,
- sizeof(fb->buffer));
- fb->offset = rules->offset;
+ if (cupsFileSeek(fb->fp, rules->offset) < 0)
+ {
+ fb->length = 0;
+ fb->offset = 0;
+ }
+ else
+ {
+ fb->length = cupsFileRead(fb->fp, (char *)fb->buffer, sizeof(fb->buffer));
+ fb->offset = rules->offset;
+ }
DEBUG_printf(("4mime_check_rules: MIME_MAGIC_INT fb->length=%d", fb->length));
}
*/
if (fb->length < 4)
+ {
result = 0;
+ }
else
{
bufptr = fb->buffer + rules->offset - fb->offset;
* Reload file buffer...
*/
- cupsFileSeek(fb->fp, rules->offset);
- fb->length = cupsFileRead(fb->fp, (char *)fb->buffer,
- sizeof(fb->buffer));
- fb->offset = rules->offset;
+ if (cupsFileSeek(fb->fp, rules->offset) < 0)
+ {
+ fb->length = 0;
+ fb->offset = 0;
+ }
+ else
+ {
+ fb->length = cupsFileRead(fb->fp, (char *)fb->buffer, sizeof(fb->buffer));
+ fb->offset = rules->offset;
+ }
DEBUG_printf(("4mime_check_rules: MIME_MAGIC_CONTAINS fb->length=%d", fb->length));
}
*/
if ((rules->offset + rules->length) > (fb->offset + fb->length))
+ {
result = 0;
+ }
else
{
if (fb->length > rules->region)
#endif /* !_WIN32 */
job->state = IPP_JSTATE_ABORTED;
}
- else if (status < 0)
- job->state = IPP_JSTATE_ABORTED;
else
fprintf(stderr, "[Job %d] Command \"%s\" completed successfully.\n", job->id, job->printer->command);
else
html_printf(client, "</table>\n");
+ cupsFreeOptions(num_options, options);
+
html_footer(client);
return (1);
num_options = get_options(&options);
if ((ipp_copies = getenv("IPP_COPIES")) != NULL)
- copies = atoi(ipp_copies);
+ {
+ if ((copies = atoi(ipp_copies)) < 1)
+ copies = 1;
+ }
else
copies = 1;
if (!strncmp(line, "%%Page:", 7))
break;
- first_pos = ftell(fp);
+ if ((first_pos = ftell(fp)) < 0)
+ {
+ perror("DEBUG: ftell failed");
+ first_pos = 0;
+ }
if (line[0] != '%')
fputs(line, stdout);
* Yes, add the service...
*/
- service = calloc(sizeof(ippfind_srv_t), 1);
+ if ((service = calloc(sizeof(ippfind_srv_t), 1)) == NULL)
+ return (NULL);
+
service->name = strdup(serviceName);
service->domain = strdup(replyDomain);
service->regtype = strdup(regtype);
* Name of test...
*/
- _ippFileReadToken(f, temp, sizeof(temp));
- _ippVarsExpand(vars, data->name, temp, sizeof(data->name));
+ if (_ippFileReadToken(f, temp, sizeof(temp)))
+ {
+ _ippVarsExpand(vars, data->name, temp, sizeof(data->name));
+ }
+ else
+ {
+ print_fatal_error(data, "Missing NAME string on line %d of \"%s\".", f->linenum, f->filename);
+ return (0);
+ }
}
else if (!_cups_strcasecmp(token, "PAUSE"))
{