Skip to content

Fix ATTR-IF-DEFINED/ATTR-IF-NOT-DEFINED handling in ippFileRead - #1779

Open
anabobillo3 wants to merge 1 commit into
OpenPrinting:masterfrom
anabobillo3:fix-ippfile-attr-if
Open

anabobillo3 wants to merge 1 commit into
OpenPrinting:masterfrom
anabobillo3:fix-ippfile-attr-if

Conversation

@anabobillo3

Copy link
Copy Markdown
Contributor

This is the CUPS master counterpart of OpenPrinting/libcups#185; cups/ipp-file.c has the same ATTR-IF-DEFINED/ATTR-IF-NOT-DEFINED code.

ippFileRead only tested the ATTR-IF-DEFINED/ATTR-IF-NOT-DEFINED variable when the attribute callback rejected the attribute name:

  • Without a callback (ipptool), the attribute was always added, whether or not the variable was defined.
  • With a callback (ippeveprinter), a name the callback rejected was still added when the condition held, and when the condition failed the value was read into the ignored message, which this branch never allocated, so the line failed with "Unsupported value".

The directive also left attr pointing at the previous attribute. An out-of-band ATTR-IF-* value adds no attribute, so a following , line appended its value to the previous attribute, possibly in a different ipp_t (ignored vs. the file's attributes). ATTR and DEFINE already reset attr.

This change tests the variable first and then the callback, allocates ignored when it is first needed, and resets attr like the other directives.

testipp gains test_file_attr_if, run without and with an attribute callback. It checks which conditional attributes end up in the message, and that a , after an out-of-band ATTR-IF-NOT-DEFINED value is reported as an error instead of adding a value to the previous attribute. On current master all four checks fail; with this change they pass, both in a --enable-debug --enable-maintainer build (make test in cups/) and under AddressSanitizer (--enable-sanitizer).

The conditional attribute directives only tested the variable when the
attribute callback rejected the name, so without a callback (ipptool) the
attribute was always added and with one (ippeveprinter) a rejected name
was added when the condition held.  Test the variable first, then the
callback, and read skipped attributes into the ignored message, which is
now allocated when first used.

Also reset the current attribute like the ATTR and DEFINE directives do,
so a "," after an out-of-band ATTR-IF-* value no longer adds a value to
the previous attribute, possibly in a different ipp_t.

Add unit tests for both cases to testipp.
@michaelrsweet michaelrsweet self-assigned this Oct 22, 2026

@michaelrsweet michaelrsweet left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to spend more time looking at this change before I accept it.

@michaelrsweet michaelrsweet added the investigating Investigating the issue label Oct 22, 2026
@michaelrsweet michaelrsweet added this to the v2.5 milestone Oct 22, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

investigating Investigating the issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants