Skip to content

Commit

Permalink
Correctly encode octetString values for print filters (Issue #5558)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
michaelrsweet committed Apr 15, 2019
1 parent cebb2dc commit 5483fd2
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Changes in CUPS v2.3b8
- The lpadmin command would hang with a bad PPD file (rdar://41495016)
- Fixed a potential crash bug in cups-driverd (rdar://46625579)
- Fixed a performance regression with large PPDs (rdar://47040759)
- The scheduler did not encode octetString values like "job-password" correctly
for the print filters (Issue #5558)
- The `ippValidateAttribute` function did not catch all instances of invalid
UTF-8 strings (Issue #5509)
- Fixed an issue with the self-signed certificates generated by GNU TLS
Expand Down
49 changes: 49 additions & 0 deletions scheduler/job.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 :
Expand Down Expand Up @@ -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 :
Expand Down

0 comments on commit 5483fd2

Please sign in to comment.