Skip to content

Commit e2aa189

Browse files
cups: Fix use-after-free in cups_enum_dests() for local destinations (Issue #1531)
1 parent 69d4be3 commit e2aa189

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

cups/dest.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3201,8 +3201,8 @@ cups_enum_dests(
32013201
// Get the list of local printers and pass them to the callback function...
32023202
num_dests = _cupsGetDests(http, IPP_OP_CUPS_GET_PRINTERS, NULL, &dests, data.type, data.mask);
32033203

3204-
data.num_local = num_dests;
3205-
data.local_dests = dests;
3204+
data.num_local = 0;
3205+
data.local_dests = NULL;
32063206

32073207
if (data.def_name[0])
32083208
{
@@ -3216,6 +3216,8 @@ cups_enum_dests(
32163216

32173217
for (i = num_dests, dest = dests; i > 0 && (!cancel || !*cancel); i --, dest ++)
32183218
{
3219+
data.num_local = cupsCopyDest(dest, data.num_local, &data.local_dests);
3220+
32193221
cups_dest_t *user_dest; // Destination from lpoptions
32203222
const char *device_uri; // Device URI
32213223

@@ -3295,6 +3297,7 @@ cups_enum_dests(
32953297
DEBUG_puts("1cups_enum_dests: Unable to create service browser, returning 0.");
32963298

32973299
cupsFreeDests(data.num_dests, data.dests);
3300+
cupsFreeDests(data.num_local, data.local_dests);
32983301
cupsArrayDelete(data.devices);
32993302

33003303
return (false);
@@ -3315,6 +3318,7 @@ cups_enum_dests(
33153318
cupsDNSSDDelete(dnssd);
33163319

33173320
cupsFreeDests(data.num_dests, data.dests);
3321+
cupsFreeDests(data.num_local, data.local_dests);
33183322
cupsArrayDelete(data.devices);
33193323

33203324
return (false);
@@ -3326,6 +3330,7 @@ cups_enum_dests(
33263330
cupsDNSSDDelete(dnssd);
33273331

33283332
cupsFreeDests(data.num_dests, data.dests);
3333+
cupsFreeDests(data.num_local, data.local_dests);
33293334
cupsArrayDelete(data.devices);
33303335

33313336
return (false);
@@ -3341,6 +3346,7 @@ cups_enum_dests(
33413346
cupsDNSSDDelete(dnssd);
33423347

33433348
cupsFreeDests(data.num_dests, data.dests);
3349+
cupsFreeDests(data.num_local, data.local_dests);
33443350
cupsArrayDelete(data.devices);
33453351

33463352
return (false);
@@ -3352,6 +3358,7 @@ cups_enum_dests(
33523358
cupsDNSSDDelete(dnssd);
33533359

33543360
cupsFreeDests(data.num_dests, data.dests);
3361+
cupsFreeDests(data.num_local, data.local_dests);
33553362
cupsArrayDelete(data.devices);
33563363

33573364
return (false);
@@ -3419,6 +3426,13 @@ cups_enum_dests(
34193426

34203427
if ((device->type & mask) != type)
34213428
device->state = _CUPS_DNSSD_INCOMPATIBLE;
3429+
3430+
if (device->state == _CUPS_DNSSD_INCOMPATIBLE)
3431+
{
3432+
DEBUG_printf("2cups_enum_dests: Skipping incompatible '%s'.",
3433+
device->fullname);
3434+
continue;
3435+
}
34223436

34233437
if (device->state == _CUPS_DNSSD_PENDING)
34243438
{

0 commit comments

Comments
 (0)