Gentoo Archives: gentoo-commits

From: "Pacho Ramos (pacho)" <pacho@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-x86 commit in x11-libs/gtk+/files: gtk+-2.24.9-printing-crash.patch
Date: Thu, 02 Feb 2012 10:23:28
Message-Id: 20120202102310.039902004B@flycatcher.gentoo.org
1 pacho 12/02/02 10:23:10
2
3 Added: gtk+-2.24.9-printing-crash.patch
4 Log:
5 Don't crash when printing, upstream bug #543520, thanks to gringo for reporting.
6
7 (Portage version: 2.1.10.44/cvs/Linux x86_64)
8
9 Revision Changes Path
10 1.1 x11-libs/gtk+/files/gtk+-2.24.9-printing-crash.patch
11
12 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/x11-libs/gtk+/files/gtk+-2.24.9-printing-crash.patch?rev=1.1&view=markup
13 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/x11-libs/gtk+/files/gtk+-2.24.9-printing-crash.patch?rev=1.1&content-type=text/plain
14
15 Index: gtk+-2.24.9-printing-crash.patch
16 ===================================================================
17 From 66c99016d3d063aee0e00793da8f087c80172012 Mon Sep 17 00:00:00 2001
18 From: Marek Kasik <mkasik@××××××.com>
19 Date: Tue, 31 Jan 2012 11:01:43 +0000
20 Subject: printing: Don't crash when printing
21
22 This commit fixes crash which occurs in Firefox, Thunderbird and Inkscape
23 during printing. This crash was caused because of wrong handling of Custom
24 CUPS options. (#543520)
25 ---
26 diff --git a/modules/printbackends/cups/gtkprintbackendcups.c b/modules/printbackends/cups/gtkprintbackendcups.c
27 index 138bddd..59914ba 100644
28 --- a/modules/printbackends/cups/gtkprintbackendcups.c
29 +++ b/modules/printbackends/cups/gtkprintbackendcups.c
30 @@ -485,7 +485,7 @@ cups_print_cb (GtkPrintBackendCups *print_backend,
31
32 typedef struct {
33 GtkCupsRequest *request;
34 - GtkPrinterOptionSet *options;
35 + GtkPrinterCups *printer;
36 } CupsOptionsData;
37
38 static void
39 @@ -495,9 +495,13 @@ add_cups_options (const gchar *key,
40 {
41 CupsOptionsData *data = (CupsOptionsData *) user_data;
42 GtkCupsRequest *request = data->request;
43 - GtkPrinterOptionSet *options = data->options;
44 - GtkPrinterOption *option = NULL;
45 + GtkPrinterCups *printer = data->printer;
46 + gboolean custom_value = FALSE;
47 gchar *new_value = NULL;
48 + gint i;
49 +
50 + if (!key || !value)
51 + return;
52
53 if (!g_str_has_prefix (key, "cups-"))
54 return;
55 @@ -505,17 +509,37 @@ add_cups_options (const gchar *key,
56 if (strcmp (value, "gtk-ignore-value") == 0)
57 return;
58
59 - option = gtk_printer_option_set_lookup (options, key);
60 -
61 key = key + strlen ("cups-");
62
63 - /* Add "Custom." prefix to custom values */
64 - if (value && option &&
65 - !gtk_printer_option_has_choice (option, value))
66 - new_value = g_strdup_printf ("Custom.%s", value);
67 + if (printer && printer->ppd_file)
68 + {
69 + ppd_coption_t *coption;
70 + gboolean found = FALSE;
71 + gboolean custom_values_enabled = FALSE;
72 +
73 + coption = ppdFindCustomOption (printer->ppd_file, key);
74 + if (coption && coption->option)
75 + {
76 + for (i = 0; i < coption->option->num_choices; i++)
77 + {
78 + /* Are custom values enabled ? */
79 + if (g_str_equal (coption->option->choices[i].choice, "Custom"))
80 + custom_values_enabled = TRUE;
81 +
82 + /* Is the value among available choices ? */
83 + if (g_str_equal (coption->option->choices[i].choice, value))
84 + found = TRUE;
85 + }
86
87 - if (new_value)
88 + if (custom_values_enabled && !found)
89 + custom_value = TRUE;
90 + }
91 + }
92 +
93 + /* Add "Custom." prefix to custom values. */
94 + if (custom_value)
95 {
96 + new_value = g_strdup_printf ("Custom.%s", value);
97 gtk_cups_request_encode_option (request, key, new_value);
98 g_free (new_value);
99 }
100 @@ -536,9 +560,6 @@ gtk_print_backend_cups_print_stream (GtkPrintBackend *print_backend,
101 CupsOptionsData *options_data;
102 GtkCupsRequest *request;
103 GtkPrintSettings *settings;
104 - GtkPrinterOptionSet *options;
105 - GtkPrintCapabilities capabilities;
106 - GtkPageSetup *page_setup;
107 const gchar *title;
108 char printer_absolute_uri[HTTP_MAX_URI];
109
110 @@ -547,8 +568,6 @@ gtk_print_backend_cups_print_stream (GtkPrintBackend *print_backend,
111
112 cups_printer = GTK_PRINTER_CUPS (gtk_print_job_get_printer (job));
113 settings = gtk_print_job_get_settings (job);
114 - capabilities = cups_printer_get_capabilities (GTK_PRINTER (cups_printer));
115 - page_setup = gtk_printer_get_default_page_size (GTK_PRINTER (cups_printer));
116
117 request = gtk_cups_request_new_with_username (NULL,
118 GTK_CUPS_POST,
119 @@ -586,16 +605,10 @@ gtk_print_backend_cups_print_stream (GtkPrintBackend *print_backend,
120 IPP_TAG_NAME, "job-name",
121 NULL, title);
122
123 - options = cups_printer_get_options (GTK_PRINTER (cups_printer), settings, page_setup, capabilities);
124 -
125 options_data = g_new0 (CupsOptionsData, 1);
126 options_data->request = request;
127 - options_data->options = options;
128 -
129 + options_data->printer = cups_printer;
130 gtk_print_settings_foreach (settings, add_cups_options, options_data);
131 -
132 - g_object_unref (page_setup);
133 - g_object_unref (options);
134 g_free (options_data);
135
136 ps = g_new0 (CupsPrintStreamData, 1);
137 @@ -4606,7 +4619,12 @@ cups_printer_get_default_page_size (GtkPrinter *printer)
138 return NULL;
139
140 option = ppdFindOption (ppd_file, "PageSize");
141 + if (option == NULL)
142 + return NULL;
143 +
144 size = ppdPageSize (ppd_file, option->defchoice);
145 + if (size == NULL)
146 + return NULL;
147
148 return create_page_setup (ppd_file, size);
149 }
150 --
151 cgit v0.9.0.2