]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Correctly encode octetString values for print filters (Issue #5558)
authorMichael R Sweet <michael.r.sweet@gmail.com>
Mon, 15 Apr 2019 20:04:28 +0000 (16:04 -0400)
committerMichael R Sweet <michael.r.sweet@gmail.com>
Mon, 15 Apr 2019 20:04:28 +0000 (16:04 -0400)
scheduler/job.c:
- get_options(): Correctly encode IPP_TAG_STRING as a quoted string or a hex
  string depending on the value.
- ipp_length(): Handle IPP_TAG_STRING separately.

CHANGES.md
scheduler/job.c

index 8b3d309053b1253168d36d0038a9ec523568c4fa..f0925f640de0dd01802b105542e203e8808fcf0e 100644 (file)
@@ -1,7 +1,14 @@
-CHANGES - 2.2.11 - 2019-03-22
+CHANGES - 2.2.12 - 2019-04-15
 =============================
 
 
+Changes in CUPS v2.2.12
+-----------------------
+
+- The scheduler did not encode octetString values like "job-password" correctly
+  for the print filters (Issue #5558)
+
+
 Changes in CUPS v2.2.11
 -----------------------
 
index 4f041388c47c9949b2dc5f26627984d4d5a68dd4..8218bfdc455cca4e173c88e4dd9de881d91367bc 100644 (file)
@@ -4021,6 +4021,45 @@ get_options(cupsd_job_t *job,            /* I - Job */
              break;
 
           case IPP_TAG_STRING :
+              {
+                int length = attr->values[i].unknown.length;
+
+               for (valptr = attr->values[i].unknown.data; length > 0; length --)
+               {
+                 if ((*valptr & 255) < 0x20 || *valptr == 0x7f)
+                   break;
+               }
+
+               if (length > 0)
+               {
+                /*
+                 * Encode this string as hex characters...
+                 */
+
+                  *optptr++ = '<';
+
+                 for (valptr = attr->values[i].unknown.data, length = attr->values[i].unknown.length; length > 0; length --)
+                 {
+                   snprintf(optptr, optlength - (size_t)(optptr - options) - 1, "%02X", *valptr & 255);
+                   optptr += 2;
+                 }
+
+                  *optptr++ = '>';
+               }
+               else
+               {
+                 for (valptr = attr->values[i].unknown.data, length = attr->values[i].unknown.length; length > 0; length --)
+                 {
+                   if (strchr(" \t\n\\\'\"", *valptr))
+                     *optptr++ = '\\';
+                   *optptr++ = *valptr++;
+                 }
+               }
+             }
+
+             *optptr = '\0';
+             break;
+
          case IPP_TAG_TEXT :
          case IPP_TAG_NAME :
          case IPP_TAG_KEYWORD :
@@ -4166,6 +4205,16 @@ ipp_length(ipp_t *ipp)                   /* I - IPP request */
          break;
 
       case IPP_TAG_STRING :
+         /*
+         * Octet strings can contain characters that need quoting.  We need
+         * at least 2 * len + 2 characters to cover the quotes and any
+         * backslashes in the string.
+         */
+
+          for (i = 0; i < attr->num_values; i ++)
+           bytes += 2 * (size_t)attr->values[i].unknown.length + 2;
+         break;
+
       case IPP_TAG_TEXT :
       case IPP_TAG_NAME :
       case IPP_TAG_KEYWORD :