summaryrefslogtreecommitdiff
path: root/scheduler
diff options
context:
space:
mode:
authorMichael R Sweet <michael.r.sweet@gmail.com>2019-04-15 16:03:03 -0400
committerMichael R Sweet <michael.r.sweet@gmail.com>2019-04-15 16:03:03 -0400
commit5483fd294a5336c2f74c87017f90ac1c159a879e (patch)
tree45d9e76ab42319f1ad1dd783aa2a6cef15e7ac7a /scheduler
parentcebb2dcc2366501b5a25fcf084da7c7cecd16c09 (diff)
downloadcups-5483fd294a5336c2f74c87017f90ac1c159a879e.tar.gz
Correctly encode octetString values for print filters (Issue #5558)
scheduler/job.c: - get_options(): Handle IPP_TAG_STRING separately and either provide a quoted string or a hex string, depending on the value. - ipp_length(): Handle IPP_TAG_STRING separately.
Diffstat (limited to 'scheduler')
-rw-r--r--scheduler/job.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/scheduler/job.c b/scheduler/job.c
index fe8eeb7c9..092d87962 100644
--- a/scheduler/job.c
+++ b/scheduler/job.c
@@ -4030,6 +4030,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 :
@@ -4175,6 +4214,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 :