cups/cups-cups-get-classes.patch
Tim Waugh aefd94790a Prevent libcups crash in cups-get-classes patch (bug #736698).
In cups_get_sdests(), when checking whether CUPS_GET_CLASSES is required
by determining whether any classes were returned by the
CUPS_GET_PRINTERS request, only call cups_find_dest() if any queues
were returned at all.
2011-09-14 12:06:07 +01:00

91 lines
2.8 KiB
Diff

diff -up cups-1.4.8/cups/dest.c.cups-get-classes cups-1.4.8/cups/dest.c
--- cups-1.4.8/cups/dest.c.cups-get-classes 2010-08-13 02:34:04.000000000 +0100
+++ cups-1.4.8/cups/dest.c 2011-09-14 12:00:56.330558590 +0100
@@ -1755,6 +1755,7 @@ cups_get_sdests(http_t *http, /* I
char uri[1024]; /* printer-uri value */
int num_options; /* Number of options */
cups_option_t *options; /* Options */
+ int get_classes; /* Whether we need to fetch class */
#ifdef __APPLE__
char media_default[41]; /* Default paper size */
#endif /* __APPLE__ */
@@ -1811,6 +1812,8 @@ cups_get_sdests(http_t *http, /* I
* printer-uri [for IPP_GET_PRINTER_ATTRIBUTES]
*/
+ get_classes = (op == CUPS_GET_PRINTERS);
+
request = ippNewRequest(op);
ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
@@ -1868,6 +1871,23 @@ cups_get_sdests(http_t *http, /* I
attr->value_tag != IPP_TAG_URI)
continue;
+ if (get_classes &&
+
+ /* Is this a class? */
+ ((attr->value_tag == IPP_TAG_ENUM &&
+ !strcmp(attr->name, "printer-type") &&
+ (attr->values[0].integer & CUPS_PRINTER_CLASS)) ||
+
+ /* Or, is this an attribute from CUPS 1.2 or later? */
+ !strcmp(attr->name, "auth-info-required") ||
+ !strncmp(attr->name, "marker-", 7) ||
+ !strcmp(attr->name, "printer-commands") ||
+ !strcmp(attr->name, "printer-is-shared")))
+ /* We are talking to a recent enough CUPS server that
+ * CUPS_GET_PRINTERS returns classes as well.
+ */
+ get_classes = 0;
+
if (!strcmp(attr->name, "auth-info-required") ||
!strcmp(attr->name, "device-uri") ||
!strcmp(attr->name, "marker-change-time") ||
@@ -1959,6 +1979,28 @@ cups_get_sdests(http_t *http, /* I
continue;
}
+ /*
+ * If we sent a CUPS_GET_CLASSES request, check whether
+ * CUPS_GET_PRINTERS already gave us this destination and exit
+ * early if so.
+ */
+
+ if (op == CUPS_GET_CLASSES && num_dests > 0)
+ {
+ int diff;
+ cups_find_dest (printer_name, NULL, num_dests, *dests, 0, &diff);
+ if (diff == 0)
+ {
+ /*
+ * Found it. The CUPS server already gave us the classes in
+ * its CUPS_GET_PRINTERS response.
+ */
+
+ cupsFreeOptions(num_options, options);
+ break;
+ }
+ }
+
if ((dest = cups_add_dest(printer_name, NULL, &num_dests, dests)) != NULL)
{
dest->num_options = num_options;
@@ -1975,6 +2017,16 @@ cups_get_sdests(http_t *http, /* I
}
/*
+ * If this is a CUPS_GET_PRINTERS request but we didn't see any
+ * classes we might be talking to an older CUPS server that requires
+ * CUPS_GET_CLASSES as well.
+ */
+
+ if (get_classes)
+ num_dests = cups_get_sdests (http, CUPS_GET_CLASSES, name,
+ num_dests, dests);
+
+ /*
* Return the count...
*/