/*
* HTTP routines for CUPS.
*
- * Copyright 2007-2018 by Apple Inc.
- * Copyright 1997-2007 by Easy Software Products, all rights reserved.
+ * Copyright © 2007-2021 by Apple Inc.
+ * Copyright © 1997-2007 by Easy Software Products, all rights reserved.
*
* This file contains Kerberos support code, copyright 2006 by
* Jelmer Vernooij.
DEBUG_printf(("2httpGetSubField2(http=%p, field=%d, name=\"%s\", value=%p, valuelen=%d)", (void *)http, field, name, (void *)value, valuelen));
+ if (value)
+ *value = '\0';
+
if (!http || !name || !value || valuelen < 2 ||
- field <= HTTP_FIELD_UNKNOWN || field >= HTTP_FIELD_MAX)
+ field <= HTTP_FIELD_UNKNOWN || field >= HTTP_FIELD_MAX || !http->fields[field])
return (NULL);
end = value + valuelen - 1;
if (http->used > 0 && ((z_stream *)http->stream)->avail_in < HTTP_MAX_BUFFER)
{
- size_t buflen = buflen = HTTP_MAX_BUFFER - ((z_stream *)http->stream)->avail_in;
+ size_t buflen = HTTP_MAX_BUFFER - ((z_stream *)http->stream)->avail_in;
/* Number of bytes to copy */
if (((z_stream *)http->stream)->avail_in > 0 &&
...) /* I - Additional args as needed */
{
ssize_t bytes; /* Number of bytes to write */
- char buf[16384]; /* Buffer for formatted string */
+ char buf[65536]; /* Buffer for formatted string */
va_list ap; /* Variable argument pointer */
DEBUG_printf(("3httpPrintf: (" CUPS_LLFMT " bytes) %s", CUPS_LLCAST bytes, buf));
- if (http->data_encoding == HTTP_ENCODING_FIELDS)
+ if (bytes > (ssize_t)(sizeof(buf) - 1))
+ {
+ http->error = ENOMEM;
+ return (-1);
+ }
+ else if (http->data_encoding == HTTP_ENCODING_FIELDS)
return ((int)httpWrite2(http, buf, (size_t)bytes));
else
{
if (_httpTLSStart(http) != 0)
{
httpAddrClose(NULL, http->fd);
+ http->fd = -1;
return (-1);
}
if (_httpTLSStart(http) != 0)
{
httpAddrClose(NULL, http->fd);
+ http->fd = -1;
*status = http->status = HTTP_STATUS_ERROR;
return (0);
char *combined; /* New value string */
- if ((combined = realloc(http->fields[field], total + 1)) != NULL)
+ if (http->fields[field] == http->_fields[field])
+ {
+ if ((combined = malloc(total + 1)) != NULL)
+ {
+ http->fields[field] = combined;
+ snprintf(combined, total + 1, "%s, %s", http->_fields[field], value);
+ }
+ }
+ else if ((combined = realloc(http->fields[field], total + 1)) != NULL)
{
http->fields[field] = combined;
strlcat(combined, ", ", total + 1);