Skip to content

Fix use-after-free in local_dests for DNS-SD discovery (Issue #1531)#1586

Open
abubakarsabir924-cell wants to merge 4 commits into
OpenPrinting:masterfrom
abubakarsabir924-cell:fix-local-printer-duplicate-1531
Open

Fix use-after-free in local_dests for DNS-SD discovery (Issue #1531)#1586
abubakarsabir924-cell wants to merge 4 commits into
OpenPrinting:masterfrom
abubakarsabir924-cell:fix-local-printer-duplicate-1531

Conversation

@abubakarsabir924-cell
Copy link
Copy Markdown
Contributor

Fixes the use-after-free bug identified by @tillkamppeter in the
local_dests pointer used during DNS-SD discovery.

Root cause: local_dests was storing a raw pointer to a list that
got freed before DNS-SD discovery ran, causing segfaults.

Changes:

  • Initialize local_dests to NULL before DNS-SD discovery starts
  • Use cupsCopyDest() in enumeration loop for proper deep copy
    instead of storing a raw pointer
  • Skip urn:uuid: prefix (+9) when comparing UUIDs — confirmed
    via http-support.c that master uses same format
  • Added cupsFreeDests() at all exit points to prevent memory leaks

Note: I don't have a setup to reproduce the issue locally.
Testing by @tillkamppeter would be appreciated.

@tillkamppeter
Copy link
Copy Markdown
Member

@abubakarsabir924-cell The code of this PR seems to be exactly what I have proposed for 2.4.x, but it seems to contain elements which @michaelrsweet has already fixed after accepting your PR #1573. Please make sure to provide your changes relative to the current state of the repo.

…#1531)

- Added check for _CUPS_DNSSD_INCOMPATIBLE state in enumeration loop
- Store UUID in device options for comparison
- Incompatible devices are now properly skipped during enumeration
- Properly copy local cupsd queues using calloc/memcpy
  instead of storing a raw pointer that gets freed
- Free local_dests copy at end of cups_enum_dests()
@abubakarsabir924-cell abubakarsabir924-cell force-pushed the fix-local-printer-duplicate-1531 branch from 79a000e to 1e6c8a7 Compare May 27, 2026 07:52
@abubakarsabir924-cell
Copy link
Copy Markdown
Contributor Author

@tillkamppeter, about the conflict — I forgot to rebase before pushing. Fixed now!

@tillkamppeter
Copy link
Copy Markdown
Member

Thanks for the rebase, but now your changes are missing some random parts of my 2.4.x patch. Please re-check. Especially the initialization of data.num_local and data.local_dests is missing.

…ing#1531)

- Initialize local_dests to NULL before DNS-SD discovery
- Use cupsCopyDest() in enumeration loop for proper deep copy
- Skip urn:uuid: prefix (9 chars) when comparing UUIDs
- Free local_dests at all exit points
@abubakarsabir924-cell abubakarsabir924-cell force-pushed the fix-local-printer-duplicate-1531 branch from 1e6c8a7 to a15637b Compare May 27, 2026 09:00
@abubakarsabir924-cell
Copy link
Copy Markdown
Contributor Author

@tillkamppeter Sir!

Fixed! Sorry for the missing initialization — I missed it during conflict resolution.

@tillkamppeter
Copy link
Copy Markdown
Member

I have tested it and it work for me now.

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