Skip to content

Commit f820a22

Browse files
Merge pull request #1618 from abubakarsabir924-cell/fix-1531-signed
cups: Fix use-after-free in cups_enum_dests() for local destinations (issue #1531)
2 parents 22dfe43 + e2aa189 commit f820a22

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
@@ -3207,8 +3207,8 @@ cups_enum_dests(
32073207
// Get the list of local printers and pass them to the callback function...
32083208
num_dests = _cupsGetDests(http, IPP_OP_CUPS_GET_PRINTERS, NULL, &dests, data.type, data.mask);
32093209

3210-
data.num_local = num_dests;
3211-
data.local_dests = dests;
3210+
data.num_local = 0;
3211+
data.local_dests = NULL;
32123212

32133213
if (data.def_name[0])
32143214
{
@@ -3222,6 +3222,8 @@ cups_enum_dests(
32223222

32233223
for (i = num_dests, dest = dests; i > 0 && (!cancel || !*cancel); i --, dest ++)
32243224
{
3225+
data.num_local = cupsCopyDest(dest, data.num_local, &data.local_dests);
3226+
32253227
cups_dest_t *user_dest; // Destination from lpoptions
32263228
const char *device_uri; // Device URI
32273229

@@ -3301,6 +3303,7 @@ cups_enum_dests(
33013303
DEBUG_puts("1cups_enum_dests: Unable to create service browser, returning 0.");
33023304

33033305
cupsFreeDests(data.num_dests, data.dests);
3306+
cupsFreeDests(data.num_local, data.local_dests);
33043307
cupsArrayDelete(data.devices);
33053308

33063309
return (false);
@@ -3321,6 +3324,7 @@ cups_enum_dests(
33213324
cupsDNSSDDelete(dnssd);
33223325

33233326
cupsFreeDests(data.num_dests, data.dests);
3327+
cupsFreeDests(data.num_local, data.local_dests);
33243328
cupsArrayDelete(data.devices);
33253329

33263330
return (false);
@@ -3332,6 +3336,7 @@ cups_enum_dests(
33323336
cupsDNSSDDelete(dnssd);
33333337

33343338
cupsFreeDests(data.num_dests, data.dests);
3339+
cupsFreeDests(data.num_local, data.local_dests);
33353340
cupsArrayDelete(data.devices);
33363341

33373342
return (false);
@@ -3347,6 +3352,7 @@ cups_enum_dests(
33473352
cupsDNSSDDelete(dnssd);
33483353

33493354
cupsFreeDests(data.num_dests, data.dests);
3355+
cupsFreeDests(data.num_local, data.local_dests);
33503356
cupsArrayDelete(data.devices);
33513357

33523358
return (false);
@@ -3358,6 +3364,7 @@ cups_enum_dests(
33583364
cupsDNSSDDelete(dnssd);
33593365

33603366
cupsFreeDests(data.num_dests, data.dests);
3367+
cupsFreeDests(data.num_local, data.local_dests);
33613368
cupsArrayDelete(data.devices);
33623369

33633370
return (false);
@@ -3425,6 +3432,13 @@ cups_enum_dests(
34253432

34263433
if ((device->type & mask) != type)
34273434
device->state = _CUPS_DNSSD_INCOMPATIBLE;
3435+
3436+
if (device->state == _CUPS_DNSSD_INCOMPATIBLE)
3437+
{
3438+
DEBUG_printf("2cups_enum_dests: Skipping incompatible '%s'.",
3439+
device->fullname);
3440+
continue;
3441+
}
34283442

34293443
if (device->state == _CUPS_DNSSD_PENDING)
34303444
{

0 commit comments

Comments
 (0)