Skip to content

driverless: escape TXT record values in the device and driver lists - #809

Merged
tillkamppeter merged 1 commit into
OpenPrinting:masterfrom
Sharadhi-v98:driverless-escape-txt-values
Nov 20, 2026
Merged

tillkamppeter merged 1 commit into
OpenPrinting:masterfrom
Sharadhi-v98:driverless-escape-txt-values

Conversation

@Sharadhi-v98

Copy link
Copy Markdown
Contributor

listPrintersInArray() takes make, model and the 1284 device ID from the DNS-SD TXT record (usb_MFG, usb_MDL, product, ty) of every IPP printer ippfind turns up and prints them unescaped inside the quoted fields of the backend discovery line (network <uri> "make-and-model" "info" "device-id" "") and of the driverless list line that cups-driverd reads. Anything on the local network can advertise those values. A " in one of them closes the field. In discovery mode the rest of the value ends up in cups-deviced's device-info, device-id and device-location. In list mode it fills cups-driverd's ppd-device-id, ppd-product, ppd-psversion and ppd-type, and the "driverless, cups-filters" text gets pushed into ppd-type. A trailing \ makes cups-deviced treat the closing quote as escaped, so it rejects the line and the printer disappears from the list.

Discovery mode now goes through cupsBackendReport(), which escapes \ and " the way cups-deviced unescapes them. backend/parallel.c already reports its devices that way. cups-driverd parses its list with sscanf("\"%127[^\"]\"...") and has no escape syntax, so list mode drops " from the three strings.

To check it, I compiled listPrintersInArray() from this file against small stubs and fed it ippfind records whose usb_MDL holds LaserJet 400" "MFG:Evil;MDL:Injected;" "Lobby or ends in a backslash. I parsed the output with copies of the CUPS 2.4 get_device() (cups-deviced) and load_drivers() (cups-driverd) field parsers. Before the patch the injected text came back as separate device-id / location / ppd-type fields and the backslash entry was dropped. With the patch every value stays inside its own field, and output for an ordinary printer is byte-identical. I don't have libcups/libcupsfilters/libppd on this machine, so the full build and the cppcheck job are left to CI.

listPrintersInArray() builds make, make-and-model and the device ID
from the DNS-SD TXT record (usb_MFG, usb_MDL, product, ty) of every IPP
printer ippfind finds, and prints them verbatim inside the quoted
fields of the backend discovery line and of the "driverless list"
line. Any host on the local network can advertise those values.

A '"' in one of them closes the field, so whatever follows lands in
device-info, device-id and device-location when cups-deviced parses
the discovery line, or in ppd-device-id, ppd-product, ppd-psversion
and ppd-type when cups-driverd parses the driver list. A trailing '\'
makes cups-deviced read the closing quote as escaped and drop the
printer.

Report the discovered device with cupsBackendReport(), which escapes
'\' and '"' the way cups-deviced unescapes them, as the parallel
backend already does. cups-driverd has no escape syntax for its
quoted fields, so drop '"' from the strings in list mode.
@tillkamppeter
tillkamppeter merged commit 4769220 into OpenPrinting:master Nov 20, 2026
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants