]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/http.c
Update ipp documentation to reflect the behavior of configuring WiFi on IPP USB printers.
[thirdparty/cups.git] / cups / http.c
index 734f9027a97581190678c18d76e6a03d1d9c7f75..43ace18f4428f7313809e644dead8b4af81a677a 100644 (file)
@@ -1,8 +1,8 @@
 /*
  * 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.
@@ -16,6 +16,7 @@
  */
 
 #include "cups-private.h"
+#include "debug-internal.h"
 #include <fcntl.h>
 #include <math.h>
 #ifdef _WIN32
@@ -1344,8 +1345,11 @@ httpGetSubField2(http_t       *http,     /* I - HTTP connection */
 
   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;
@@ -1729,7 +1733,7 @@ httpPeek(http_t *http,                    /* I - HTTP connection */
 
     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 &&
@@ -1856,7 +1860,7 @@ httpPrintf(http_t     *http,              /* I - HTTP connection */
           ...)                         /* 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 */
 
 
@@ -1868,7 +1872,12 @@ httpPrintf(http_t     *http,             /* I - HTTP connection */
 
   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
   {
@@ -2412,6 +2421,7 @@ httpReconnect2(http_t *http,              /* I - HTTP connection */
     if (_httpTLSStart(http) != 0)
     {
       httpAddrClose(NULL, http->fd);
+      http->fd = -1;
 
       return (-1);
     }
@@ -2777,6 +2787,7 @@ _httpUpdate(http_t        *http,  /* I - HTTP connection */
       if (_httpTLSStart(http) != 0)
       {
         httpAddrClose(NULL, http->fd);
+        http->fd = -1;
 
        *status = http->status = HTTP_STATUS_ERROR;
        return (0);
@@ -3643,7 +3654,15 @@ http_add_field(http_t       *http,       /* I - HTTP connection */
 
     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);