michaelrsweet / pappl

PAPPL - Printer Application Framework
https://www.msweet.org/pappl
Apache License 2.0
309 stars 49 forks source link

printer-driver.c: Fix crash when adding generic PS printer #322

Closed zdohnal closed 9 months ago

zdohnal commented 9 months ago

If legacy-printer-app is run for the first time and generic PS driver was chosen when installing the printer, the application crashes during adding the printer.

It is because the printer structure does not have device_id set, and the library tries to get data from already freed printer->driver_attrs. Additionally, if the device id exists in the printer, it rewrites incorrect structure (we should set device id attr in attrs, which we return).

The fix adds possibility to extract device id from printer->attrs and if device id is missing in printer->attrs and document-format-supported as well, try document-format-default and if this attribute is missing, return NULL.

zdohnal commented 9 months ago

The key for reproducing the issue is that it must be the first run of legacy-printer-app after its installation and start. I was not able to reproduce in other runs.

michaelrsweet commented 9 months ago

Hard to diagnose this without a backtrace...

zdohnal commented 9 months ago

Full backtrace of the crash - the program crashes in libcups, because it tries to access invalid memory, which was freed in pappl, however it is accessed later during generating driver attributes. It is the thread 1, in ippFindNextAttribute() function.

michaelrsweet commented 9 months ago

[master 47cfc65] Fix printer-device-id (Issue #322)

[v1.4.x 8820820] Bump version/copyright.

zdohnal commented 9 months ago

Thank you for the fix, Mike! It works in my testing env.