From 04cc34625677b6dcd851da7b6e77af00805ed66d Mon Sep 17 00:00:00 2001 From: ManasBagul23 Date: Thu, 5 Nov 2026 11:19:10 +0530 Subject: [PATCH] cups-browsed: fix double free in add_enum_attributes/add_margin_attributes Both functions build a de-duplicated list of values seen across the printers in a cluster using a single reusable "str" scratch buffer: each candidate value is snprintf'd into it, looked up in the array, and (if not already present) added to the array by that same pointer. Since the array only ever contains that one scratch address, every later cupsArrayFind() call compares the buffer against itself and always reports "found", so exactly one value ever gets added no matter how many distinct values are actually seen -- the merged cluster attribute silently loses all but the first value. Worse, after the loop the code does "free(str)" and then cupsArrayDelete(list), which frees every element still in the array -- that same str pointer -- a second time. Any cluster where the attribute has at least one value (print-quality-supported, finishings-supported, the media margins, etc. are all common) hits this double free. Add a strdup() of the scratch buffer's contents to the array instead of the scratch pointer itself, so each entry is independently owned, compared by content as intended, and freed exactly once. --- 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..9f3f5092 100644 --- a/daemon/cups-browsed.c +++ b/daemon/cups-browsed.c @@ -1464,7 +1464,7 @@ add_enum_attributes(char* cluster_name, snprintf(str, 16, "%d", value); if (!cupsArrayFind(list, (void *)str)) { - cupsArrayAdd(list, (void *)str); + cupsArrayAdd(list, (void *)strdup(str)); num_value++; } } @@ -1539,7 +1539,7 @@ add_margin_attributes(char* cluster_name, snprintf(str, 16, "%d", value); if (!cupsArrayFind(list, (void *)str)) { - cupsArrayAdd(list, (void *)str); + cupsArrayAdd(list, (void *)strdup(str)); num_value++; } }