]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Fix form decode problems.
authorMichael R Sweet <msweet@msweet.org>
Tue, 28 May 2024 21:05:12 +0000 (17:05 -0400)
committerMichael R Sweet <msweet@msweet.org>
Tue, 28 May 2024 21:05:12 +0000 (17:05 -0400)
cups/form.c

index e5091aac0f25fa9eae74641e5ee2fe4c1e21bc32..f10c387dc8799232b52282a1b3c567688d7e0e97 100644 (file)
@@ -41,6 +41,8 @@ cupsFormDecode(const char    *data,   // I - URL-encoded form data
                value[4096];            // Variable value
 
 
+  DEBUG_printf("cupsFormDecode(data=\"%s\", vars=%p)", data, (void *)vars);
+
   // Range check...
   if (vars)
     *vars = NULL;
@@ -65,17 +67,23 @@ cupsFormDecode(const char    *data, // I - URL-encoded form data
   while (*data)
   {
     // Get the name and value...
+    DEBUG_printf("2cupsFormDecode: LOOP data=%p, *data='%c'", data, data ? *data : '?');
     data = decode_string(data, name, sizeof(name));
 
     if (!data || *data != '=')
+    {
+      DEBUG_printf("2cupsFormDecode: NAMEERROR data=%p, *data='%c'", data, data ? *data : '?');
       goto decode_error;
+    }
 
+    DEBUG_printf("2cupsFormDecode: name=\"%s\"", name);
     data ++;
 
     data = decode_string(data, value, sizeof(value));
 
     if (!data || (*data && *data != '&'))
     {
+      DEBUG_printf("2cupsFormDecode: VALUEERROR data=%p, *data='%c'", data, data ? *data : '?');
       goto decode_error;
     }
     else if (*data)
@@ -83,13 +91,20 @@ cupsFormDecode(const char    *data, // I - URL-encoded form data
       data ++;
 
       if (!*data)
+      {
+       DEBUG_printf("2cupsFormDecode: POSTERROR data=%p, *data='%c'", data, data ? *data : '?');
         goto decode_error;
+      }
     }
 
+    DEBUG_printf("2cupsFormDecode: value=\"%s\"", value);
+
     // Add the variable...
     num_vars = cupsAddOption(name, value, num_vars, vars);
   }
 
+  DEBUG_printf("2cupsFormDecode: Returning %lu", (unsigned long)num_vars);
+
   return (num_vars);
 
   // If we get here there was an error in the form data...
@@ -100,6 +115,8 @@ cupsFormDecode(const char    *data, // I - URL-encoded form data
   _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Invalid form data."), 1);
   *vars = NULL;
 
+  DEBUG_puts("2cupsFormDecode: Returning 0");
+
   return (0);
 }
 
@@ -216,7 +233,7 @@ decode_string(const char *data,         // I - Pointer into data string
        *end;                           // Pointer to end of buffer
 
 
-  for (ptr = buffer, end = buffer + bufsize - 1; isalnum(*data & 255) || *data == '%' || *data == '+'; data ++)
+  for (ptr = buffer, end = buffer + bufsize - 1; *data && *data != '&' && *data != '='; data ++)
   {
     if ((ch = *data) == '+')
     {