Skip to content

Commit

Permalink
Fix encoding of extension values (Issue #80)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelrsweet committed Mar 25, 2024
1 parent c370400 commit bf38abb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 35 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -25,6 +25,7 @@ libcups v3.0rc1 (TBD)
- Fixed JSON output from `ipptool`.
- Fixed hang/crash in `cupsEnumDests`/`cupsGetDests` (Issue #74)
- Fixed encoding of IPv6 addresses in HTTP requests (Issue #78)
- Fixed encoding of `IPP_TAG_EXTENSION` values in IPP messages (Issue #80)


libcups v3.0b2 (October 5, 2023)
Expand Down
47 changes: 13 additions & 34 deletions cups/ipp.c
Expand Up @@ -2085,7 +2085,7 @@ ippGetOctetString(
size_t *datalen) // O - Length of octetString data
{
// Range check input...
if (!attr || attr->value_tag != IPP_TAG_STRING || element >= attr->num_values)
if (!attr || (attr->value_tag != IPP_TAG_STRING && attr->value_tag != IPP_TAG_EXTENSION) || element >= attr->num_values)
{
if (datalen)
*datalen = 0;
Expand Down Expand Up @@ -2563,25 +2563,6 @@ ippReadIO(void *src, // I - Data source

// Read this attribute...
tag = (ipp_tag_t)buffer[0];
if (tag == IPP_TAG_EXTENSION)
{
// Read 32-bit "extension" tag...
if ((*cb)(src, buffer, 4) < 4)
{
DEBUG_puts("1ippReadIO: Callback returned EOF/error");
goto rollback;
}

tag = (ipp_tag_t)((buffer[0] << 24) | (buffer[1] << 16) | (buffer[2] << 8) | buffer[3]);

if (tag & IPP_TAG_CUPS_CONST)
{
// Fail if the high bit is set in the tag...
_cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("IPP extension tag larger than 0x7FFFFFFF."), 1);
DEBUG_printf("1ippReadIO: bad tag 0x%x.", tag);
goto rollback;
}
}

if (tag == IPP_TAG_END)
{
Expand Down Expand Up @@ -3387,7 +3368,7 @@ ippSetOctetString(


// Range check input...
if (!ipp || !attr || !*attr || ((*attr)->value_tag != IPP_TAG_STRING && (*attr)->value_tag != IPP_TAG_NOVALUE && (*attr)->value_tag != IPP_TAG_UNKNOWN) || element > (*attr)->num_values || datalen > IPP_MAX_LENGTH)
if (!ipp || !attr || !*attr || ((*attr)->value_tag != IPP_TAG_STRING && (*attr)->value_tag != IPP_TAG_NOVALUE && (*attr)->value_tag != IPP_TAG_UNKNOWN && (*attr)->value_tag != IPP_TAG_EXTENSION) || element > (*attr)->num_values || datalen > IPP_MAX_LENGTH)
return (false);

// Set the value and return...
Expand Down Expand Up @@ -3948,6 +3929,16 @@ ippSetValueTag(
if (temp_tag == IPP_TAG_NAME || temp_tag == IPP_TAG_NAMELANG)
break; // Silently "allow" name -> keyword

return (false);

case IPP_TAG_EXTENSION :
if (temp_tag == IPP_TAG_STRING && value_tag == IPP_TAG_EXTENSION)
{
// Allow octetString -> extension
(*attr)->value_tag = value_tag;
break;
}

default :
return (false);
}
Expand Down Expand Up @@ -4717,19 +4708,7 @@ ippWriteIO(void *dst, // I - Destination
DEBUG_printf("2ippWriteIO: writing value tag=%x(%s)", attr->value_tag, ippTagString(attr->value_tag));
DEBUG_printf("2ippWriteIO: writing name=%d,\"%s\"", n, attr->name);

if (attr->value_tag > 0xff)
{
*bufptr++ = IPP_TAG_EXTENSION;
*bufptr++ = (ipp_uchar_t)(attr->value_tag >> 24);
*bufptr++ = (ipp_uchar_t)(attr->value_tag >> 16);
*bufptr++ = (ipp_uchar_t)(attr->value_tag >> 8);
*bufptr++ = (ipp_uchar_t)attr->value_tag;
}
else
{
*bufptr++ = (ipp_uchar_t)attr->value_tag;
}

*bufptr++ = (ipp_uchar_t)attr->value_tag;
*bufptr++ = (ipp_uchar_t)(n >> 8);
*bufptr++ = (ipp_uchar_t)n;
memcpy(bufptr, attr->name, (size_t)n);
Expand Down
2 changes: 1 addition & 1 deletion cups/ipp.h
Expand Up @@ -484,7 +484,7 @@ typedef enum ipp_tag_e // Value and group tag values for attributes
IPP_TAG_LANGUAGE, // Language value
IPP_TAG_MIMETYPE, // MIME media type value
IPP_TAG_MEMBERNAME, // Collection member name value
IPP_TAG_EXTENSION = 0x7f, // Extension point for 32-bit tags
IPP_TAG_EXTENSION = 0x7f, // Extension point for 32-bit tags (part of value)
IPP_TAG_CUPS_MASK = 0x7fffffff, // Mask for copied attribute values
// The following expression is used to avoid compiler warnings with +/-0x80000000
IPP_TAG_CUPS_CONST = -0x7fffffff-1 // Bitflag for copied/const attribute values
Expand Down

0 comments on commit bf38abb

Please sign in to comment.