summaryrefslogtreecommitdiff
path: root/debian/patches/01_foomatic-rip-error-out-on-problems-longer-string-buffers.patch
blob: 7709dabcb896d6d63535a0c7fab884ef206c2132 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
Description:  Let foomatic-rip actually error out if something goes wrong. It
 simply continued or closed silently (exit status 0) on several issues (LP:
 #570522). Also make string buffers bigger as many of them were too small.
 This patch contains the changes which are planned to be introduced in
 Foomatic 4.0.5, so this can be considered a test release for 4.0.5.
Origin: upstream
Author: Till Kamppeter <till.kamppeter@gmail.com>
Last-Update: 2010-06-08
Index: foomatic-filters/ChangeLog
===================================================================
--- foomatic-filters.orig/ChangeLog	2010-07-19 16:40:10.000000000 +0200
+++ foomatic-filters/ChangeLog	2010-07-25 16:08:04.000000000 +0200
@@ -1,3 +1,32 @@
+2010-06-08  Till Kamppeter <till.kamppeter@gmail.com>
+
+	* USAGE: Documentation correction.
+
+2010-06-07  Till Kamppeter <till.kamppeter@gmail.com>
+
+	* USAGE: Finally completed the documentation update to reflect that
+	  the Ghostscript library is not needed any more.
+
+	* foomaticrip.c, foomaticrip.h, pdf.c: Let foomatic-rip actually
+	  error out if something goes wrong. It simply continued or closed
+	  silently (exit status 0) on the following events: Failure of
+	  print_file() function call, failure of Ghostscript to determine
+	  the number of pages of a PDF input file (causes Ubuntu bug
+	  #570522), failure to start Ghostscript to render a PDF file,
+	  failure to create a temporary file for extracting selected pages
+	  from a PDF file, failure to run Ghostscript to extract pages from
+	  a PDF file, page count result being a negative number.
+
+	* foomaticrip.c: Use EXIT_PRINTED constant and not hard-coded "0"
+	  as exit value when terminating successfully.
+
+	* foomaticrip.h: Correct definition of EXIT_STARVED constant.
+
+2010-03-26  Till Kamppeter <till.kamppeter@gmail.com>
+
+	* options.c, options.h: Made some strings longer, to avoid space
+	  problems.
+
 2010-02-15  Till Kamppeter <till.kamppeter@gmail.com>
 
 	* Tagged branch for release 4.0.4.
Index: foomatic-filters/USAGE
===================================================================
--- foomatic-filters.orig/USAGE	2010-07-19 16:40:10.000000000 +0200
+++ foomatic-filters/USAGE	2010-07-25 16:08:04.000000000 +0200
@@ -74,9 +74,8 @@
 Foomatic runs on all systems where one can run the Perl
 interpreter and Ghostscript.
 
-foomatic-filters needs the Ghostscript library for foomatic-rip and
-the Perl interpreter for beh (Backend Error Handler) and the test
-suite.
+foomatic-filters needs the Perl interpreter for beh (Backend Error
+Handler) and the test suite.
 
 To build foomatic-rip you need a C compiler and its standard libraries.
 
@@ -138,9 +137,8 @@
 a normal user.
 
 The "configure" script will auto-detect where the programs have to be
-installed and where the Perl interpreter and the Ghostscript library
-are located. If "configure" fails because of something not being
-installed, do
+installed and where the Perl interpreter is located. If "configure"
+fails because of something not being installed, do
 
    rm -rf config.cache autom*.cache
 
Index: foomatic-filters/foomaticrip.c
===================================================================
--- foomatic-filters.orig/foomaticrip.c	2010-07-19 16:40:10.000000000 +0200
+++ foomatic-filters/foomaticrip.c	2010-07-25 16:08:04.000000000 +0200
@@ -1602,7 +1602,8 @@
            PostScript file (all before the first page begins). */
         optionset_copy_values(optionset("userval"), optionset("header"));
 
-        print_file(filename, 1);
+        if (!print_file(filename, 1))
+	    rip_die(EXIT_PRNERR_NORETRY, "Could not print file %s\n", filename);
         filename = strtok_r(NULL, " ", &p);
     }
 
@@ -1639,6 +1640,6 @@
 
     list_free(arglist);
 
-    return 0;
+    return EXIT_PRINTED;
 }
 
Index: foomatic-filters/foomaticrip.h
===================================================================
--- foomatic-filters.orig/foomaticrip.h	2010-07-19 16:40:10.000000000 +0200
+++ foomatic-filters/foomaticrip.h	2010-07-25 16:08:04.000000000 +0200
@@ -56,7 +56,7 @@
 #define EXIT_JOBERR 3                           /* job is defective */
 #define EXIT_SIGNAL 4                           /* terminated after catching signal */
 #define EXIT_ENGAGED 5                          /* printer is otherwise engaged (connection refused) */
-#define EXIT_STARVED = 6;                       /* starved for system resources */
+#define EXIT_STARVED 6                          /* starved for system resources */
 #define EXIT_PRNERR_NORETRY_ACCESS_DENIED 7     /* bad password? bad port permissions? */
 #define EXIT_PRNERR_NOT_RESPONDING 8            /* just doesn't answer at all (turned off?) */
 #define EXIT_PRNERR_NORETRY_BAD_SETTINGS 9      /* interface settings are invalid */
Index: foomatic-filters/options.c
===================================================================
--- foomatic-filters.orig/options.c	2010-07-19 16:40:10.000000000 +0200
+++ foomatic-filters/options.c	2010-07-25 16:08:04.000000000 +0200
@@ -34,10 +34,10 @@
 
 /* Values from foomatic keywords in the ppd file */
 char printer_model [256];
-char printer_id [128];
+char printer_id [256];
 char driver [128];
-char cmd [1024];
-char cmd_pdf [1024];
+char cmd [4096];
+char cmd_pdf [4096];
 dstr_t *postpipe = NULL;  /* command into which the output of this
                              filter should be piped */
 int ps_accounting = 1;
@@ -751,7 +751,7 @@
     {
         choice_t *choice = option_find_choice(opt, "Custom");
         char ** paramvalues = paramvalues_from_string(opt, values);
-        char width[30], height[20];
+        char width[30], height[30];
         int pos;
 
         assert(choice);
@@ -1215,7 +1215,7 @@
     }
 
     if (!startswith(code, "%% FoomaticRIPOptionSetting"))
-        unhtmlify(choice->command, 1024, code);
+        unhtmlify(choice->command, 65536, code);
 }
 
 /*
@@ -1529,10 +1529,10 @@
             unhtmlify(postpipe->data, postpipe->alloc, value->data);
         }
         else if (strcmp(key, "FoomaticRIPCommandLine") == 0) {
-            unhtmlify(cmd, 1024, value->data);
+            unhtmlify(cmd, 4096, value->data);
         }
         else if (strcmp(key, "FoomaticRIPCommandLinePDF") == 0) {
-            unhtmlify(cmd_pdf, 1024, value->data);
+            unhtmlify(cmd_pdf, 4096, value->data);
         }
         else if (strcmp(key, "FoomaticRIPNoPageAccounting") == 0) {
             /* Boolean value */
@@ -1742,7 +1742,7 @@
      * line */
     if (startswith(cmd, "gs"))
     {
-        strncpy(cmd_pdf, cmd, 1024);
+        strncpy(cmd_pdf, cmd, 4096);
         return 1;
     }
 
Index: foomatic-filters/options.h
===================================================================
--- foomatic-filters.orig/options.h	2010-07-19 16:40:10.000000000 +0200
+++ foomatic-filters/options.h	2010-07-25 16:08:04.000000000 +0200
@@ -55,7 +55,7 @@
 typedef struct choice_s {
     char value [128];
     char text [128];
-    char command[1024];
+    char command[65536];
     struct choice_s *next;
 } choice_t;
 
@@ -125,8 +125,8 @@
 extern char jclend[256];
 extern char jclprefix[256];
 
-extern char cmd[1024];
-extern char cmd_pdf[1024];
+extern char cmd[4096];
+extern char cmd_pdf[4096];
 
 extern int ps_accounting;
 
Index: foomatic-filters/pdf.c
===================================================================
--- foomatic-filters.orig/pdf.c	2010-07-19 16:40:10.000000000 +0200
+++ foomatic-filters/pdf.c	2010-07-25 16:08:04.000000000 +0200
@@ -52,10 +52,8 @@
 	     gspath, filename);
 
     FILE *pd = popen(gscommand, "r");
-    if (!pd) {
-      _log("Failed to execute ghostscript to determine number of input pages!\n");
-        return 0;
-    }
+    if (!pd)
+      rip_die(EXIT_STARVED, "Failed to execute ghostscript to determine number of input pages!\n");
 
     fread(output, 1, 31, pd);
     pclose(pd);
@@ -77,7 +75,7 @@
     _log("Starting renderer with command: %s\n", cmd);
     kid3 = start_process("kid3", exec_kid3, (void *)cmd, NULL, NULL);
     if (kid3 < 0)
-        return 0;
+        rip_die(EXIT_STARVED, "Could not start renderer\n");
 
     return 1;
 }
@@ -118,7 +116,7 @@
     snprintf(filename, PATH_MAX, "%s/foomatic-XXXXXX", temp_dir());
     mktemp(filename);
     if (!filename[0])
-        return 0;
+        rip_die(EXIT_STARVED, "Unable to create temporary file!\n");
 
     snprintf(filename_arg, PATH_MAX, "-sOutputFile=%s", filename);
     snprintf(first_arg, 50, "-dFirstPage=%d", first);
@@ -132,10 +130,8 @@
 	     gspath, filename_arg, first_arg, last_arg, pdffilename);
 
     FILE *pd = popen(gscommand, "r");
-    if (!pd) {
-        _log("Could not run ghostscript to extract the pages!\n");
-        return 0;
-    }
+    if (!pd)
+        rip_die(EXIT_STARVED, "Could not run ghostscript to extract the pages!\n");
     pclose(pd);
 
     return 1;
@@ -158,7 +154,7 @@
     else
     {
         if (!pdf_extract_pages(tmpfile, filename, firstpage, lastpage))
-            return 0;
+            rip_die(EXIT_STARVED, "Could not run ghostscript to extract the pages!\n");
         dstrcatf(cmd, " < %s", tmpfile);
     }
 
@@ -237,7 +233,7 @@
     page_count = pdf_count_pages(filename);
 
     if (page_count <= 0)
-        return 0;
+        rip_die(EXIT_JOBERR, "Unable to determine number of pages, page count: %d\n", page_count);
     _log("File contains %d pages\n", page_count);
 
     optionset_copy_values(optionset("header"), optionset("currentpage"));