From 00ea819c5263220ccdc2260b3a756ea717ca929e Mon Sep 17 00:00:00 2001 From: ManasBagul23 Date: Thu, 5 Nov 2026 11:53:42 +0530 Subject: [PATCH] cups-browsed: fix invalid free of pdl_list entries in on_job_state When picking the document format to hand a job to in on_job_state(), pdl_list is a cupsArray with free() as its destructor, but the entries added to it are never our own: when a document-format- supported attribute is available they're ippGetString() values owned by the printer's own prattrs IPP message, and when we fall back to the DNS-SD "pdl" string they're pointers into the *middle* of that one string (format is walked forward token by token, nothing is copied out). Either way, cupsArrayDelete(pdl_list) ends up calling free() on memory it was never given ownership of -- an interior pointer isn't even something malloc() returned, so this is corruption waiting to happen, and it runs on every job sent to an implicit-class/cluster queue. Store a strdup() of each format string instead, and skip NULL results from ippGetString() instead of handing them to strcasecmp. --- daemon/cups-browsed.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/daemon/cups-browsed.c b/daemon/cups-browsed.c index 0b3e4859..8c33bdbd 100644 --- a/daemon/cups-browsed.c +++ b/daemon/cups-browsed.c @@ -5926,8 +5926,8 @@ on_job_state (CupsNotifier *object, // Pick next format from attribute if (attr) format = ippGetString(attr, i, NULL); // Add format to list of supported PDLs, skip duplicates - if (!cupsArrayFind(pdl_list, (void *)format)) - cupsArrayAdd(pdl_list, (void *)format); + if (format && !cupsArrayFind(pdl_list, (void *)format)) + cupsArrayAdd(pdl_list, (void *)strdup(format)); if (attr) // Next format in attribute i ++;