Skip to content

Commit 1097cf7

Browse files
committed
udev-configure-printer.c: Fix possible use after frees and leaks
1 parent 22f8c8f commit 1097cf7

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

udev/udev-configure-printer.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,12 @@ add_device_uri (struct device_uris *uris,
205205
uris->n_uris = 1;
206206
uris->uri[0] = uri_copy;
207207
}
208+
else
209+
{
210+
syslog (LOG_ERR, "out of memory");
211+
free (uri_copy);
212+
return;
213+
}
208214
}
209215
else
210216
{
@@ -847,6 +853,7 @@ device_id_from_devpath (struct udev *udev, const char *devpath,
847853

848854
udev_device_unref (dev);
849855
free (devicefilepath);
856+
g_free(device_id);
850857
return usb_device_devpath;
851858
}
852859

@@ -1274,7 +1281,6 @@ find_matching_device_uris (struct device_id *id,
12741281
{
12751282
add_usb_uri_mapping (&map, devpath, uris);
12761283
write_usb_uri_map (map);
1277-
free_usb_uri_map (map);
12781284
}
12791285

12801286
return uris->n_uris;
@@ -1527,6 +1533,11 @@ for_each_matching_queue (struct device_uris *device_uris,
15271533
free(this_device_uri_n);
15281534
this_device_uri_n = NULL;
15291535
}
1536+
if (device_uri_n != NULL)
1537+
{
1538+
free(device_uri_n);
1539+
device_uri_n = NULL;
1540+
}
15301541
if (!attr)
15311542
break;
15321543
}
@@ -1625,6 +1636,7 @@ do_add (const char *cmd, const char *devaddr)
16251636
if (udev == NULL)
16261637
{
16271638
syslog (LOG_ERR, "udev_new failed");
1639+
free_usb_uri_map (map);
16281640
exit (1);
16291641
}
16301642

@@ -1643,7 +1655,7 @@ do_add (const char *cmd, const char *devaddr)
16431655
if (!id.mfg || !id.mdl)
16441656
{
16451657
clear_device_id (&id);
1646-
free (map);
1658+
free_usb_uri_map (map);
16471659
free (usb_device_devpath);
16481660
return 1;
16491661
}
@@ -1668,7 +1680,7 @@ do_add (const char *cmd, const char *devaddr)
16681680
{
16691681
syslog (LOG_ERR, "no corresponding CUPS device found");
16701682
clear_device_id (&id);
1671-
free (map);
1683+
free_usb_uri_map (map);
16721684
return 0;
16731685
}
16741686

@@ -1722,7 +1734,7 @@ do_add (const char *cmd, const char *devaddr)
17221734

17231735
clear_device_id (&id);
17241736
free_device_uris (&device_uris);
1725-
free (map);
1737+
free_usb_uri_map (map);
17261738
return 0;
17271739
}
17281740

0 commit comments

Comments
 (0)