enscript.patch 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. Security bugfixes (CAN-2004-1184, CAN-2004-1185, CAN-2004-1186)
  2. and some additional non-security bugfixes.
  3. Index: compat/regex.c
  4. --- compat/regex.c.orig 1998-10-20 15:39:02 +0200
  5. +++ compat/regex.c 2005-02-05 09:50:45 +0100
  6. @@ -2400,11 +2400,13 @@
  7. case ')':
  8. if (syntax & RE_NO_BK_PARENS) goto normal_backslash;
  9. - if (COMPILE_STACK_EMPTY)
  10. - if (syntax & RE_UNMATCHED_RIGHT_PAREN_ORD)
  11. + if (COMPILE_STACK_EMPTY) {
  12. + if (syntax & RE_UNMATCHED_RIGHT_PAREN_ORD) {
  13. goto normal_backslash;
  14. - else
  15. + } else {
  16. FREE_STACK_RETURN (REG_ERPAREN);
  17. + }
  18. + }
  19. handle_close:
  20. if (fixup_alt_jump)
  21. @@ -2420,11 +2422,13 @@
  22. }
  23. /* See similar code for backslashed left paren above. */
  24. - if (COMPILE_STACK_EMPTY)
  25. - if (syntax & RE_UNMATCHED_RIGHT_PAREN_ORD)
  26. + if (COMPILE_STACK_EMPTY) {
  27. + if (syntax & RE_UNMATCHED_RIGHT_PAREN_ORD) {
  28. goto normal_char;
  29. - else
  30. + } else {
  31. FREE_STACK_RETURN (REG_ERPAREN);
  32. + }
  33. + }
  34. /* Since we just checked for an empty stack above, this
  35. ``can't happen''. */
  36. Index: docs/Makefile.in
  37. --- docs/Makefile.in.orig 2002-01-24 08:39:44 +0100
  38. +++ docs/Makefile.in 2005-02-05 09:50:45 +0100
  39. @@ -284,7 +284,7 @@
  40. enscript.fns enscript.ky enscript.kys enscript.ps \
  41. enscript.log enscript.pg enscript.toc enscript.tp \
  42. enscript.tps enscript.vr enscript.vrs enscript.op enscript.tr \
  43. - enscript.cv enscript.cn
  44. + enscript.cv enscript.cn enscript.1 states.1
  45. clean-aminfo:
  46. Index: docs/enscript.man
  47. --- docs/enscript.man.orig 2000-11-30 07:55:31 +0100
  48. +++ docs/enscript.man 2005-02-05 09:50:45 +0100
  49. @@ -118,7 +118,7 @@
  50. The header string \f2header\f1 can contain the same formatting escapes
  51. which can be specified for the \f3%Format\f1 directives in the user
  52. defined fancy headers. For example, the following option prints the
  53. -file name, current data and page numbers:
  54. +file name, current date and page numbers:
  55. \f3enscript \-\-header='$n %W Page $% of $=' *.c\f1
  56. Index: lib/enscript-color.hdr
  57. --- lib/enscript-color.hdr.orig 1998-12-29 09:40:47 +0100
  58. +++ lib/enscript-color.hdr 2005-02-05 09:50:45 +0100
  59. @@ -27,8 +27,8 @@
  60. % -- code follows this line --
  61. %%DocumentNeededResources: font Times-Bold Times-Roman
  62. -%Format: moddatestr $W
  63. -%Format: modtimestr $C
  64. +%Format: moddatestr $D{%x}
  65. +%Format: modtimestr $D{%X}
  66. %Format: pagenumstr $%
  67. %Format: pagecountstr /$=
  68. Index: lib/enscript.hdr
  69. --- lib/enscript.hdr.orig 1997-03-03 09:20:34 +0100
  70. +++ lib/enscript.hdr 2005-02-05 09:50:45 +0100
  71. @@ -25,8 +25,8 @@
  72. % -- code follows this line --
  73. %%DocumentNeededResources: font Times-Bold Times-Roman
  74. -%Format: moddatestr $W
  75. -%Format: modtimestr $C
  76. +%Format: moddatestr $D{%x}
  77. +%Format: modtimestr $D{%X}
  78. %Format: pagenumstr $%
  79. % Fonts.
  80. Index: src/gsint.h
  81. --- src/gsint.h.orig 2000-07-11 17:28:06 +0200
  82. +++ src/gsint.h 2005-02-05 09:50:45 +0100
  83. @@ -701,4 +701,9 @@
  84. */
  85. void printer_close ___P ((void *context));
  86. +/*
  87. + * Escape filenames for shell usage
  88. + */
  89. +char *shell_escape ___P ((const char *fn));
  90. +
  91. #endif /* not GSINT_H */
  92. Index: src/main.c
  93. --- src/main.c.orig 2002-01-24 08:35:45 +0100
  94. +++ src/main.c 2005-02-05 09:50:45 +0100
  95. @@ -973,6 +973,8 @@
  96. */
  97. #if HAVE_LC_MESSAGES
  98. setlocale (LC_MESSAGES, "");
  99. + setlocale (LC_CTYPE, "");
  100. + setlocale (LC_TIME, "");
  101. #endif
  102. #endif
  103. #if ENABLE_NLS
  104. @@ -1546,9 +1548,13 @@
  105. buffer_append (&cmd, intbuf);
  106. buffer_append (&cmd, " ");
  107. - buffer_append (&cmd, "-Ddocument_title=\"");
  108. - buffer_append (&cmd, title);
  109. - buffer_append (&cmd, "\" ");
  110. + buffer_append (&cmd, "-Ddocument_title=\'");
  111. + if ((cp = shell_escape (title)) != NULL)
  112. + {
  113. + buffer_append (&cmd, cp);
  114. + free (cp);
  115. + }
  116. + buffer_append (&cmd, "\' ");
  117. buffer_append (&cmd, "-Dtoc=");
  118. buffer_append (&cmd, toc ? "1" : "0");
  119. @@ -1565,8 +1571,14 @@
  120. /* Append input files. */
  121. for (i = optind; i < argc; i++)
  122. {
  123. - buffer_append (&cmd, " ");
  124. - buffer_append (&cmd, argv[i]);
  125. + char *cp;
  126. + if ((cp = shell_escape (argv[i])) != NULL)
  127. + {
  128. + buffer_append (&cmd, " \'");
  129. + buffer_append (&cmd, cp);
  130. + buffer_append (&cmd, "\'");
  131. + free (cp);
  132. + }
  133. }
  134. /* And do the job. */
  135. @@ -1627,7 +1639,7 @@
  136. buffer_ptr (opts), buffer_len (opts));
  137. }
  138. - buffer_append (&buffer, " \"%s\"");
  139. + buffer_append (&buffer, " \'%s\'");
  140. input_filter = buffer_copy (&buffer);
  141. input_filter_stdin = "-";
  142. Index: src/mkafmmap.c
  143. --- src/mkafmmap.c.orig 1997-07-03 13:14:59 +0200
  144. +++ src/mkafmmap.c 2005-02-05 09:50:45 +0100
  145. @@ -126,6 +126,7 @@
  146. #if HAVE_SETLOCALE
  147. #if HAVE_LC_MESSAGES
  148. setlocale (LC_MESSAGES, "");
  149. + setlocale (LC_CTYPE, "");
  150. #endif
  151. #endif
  152. #if ENABLE_NLS
  153. Index: src/psgen.c
  154. --- src/psgen.c.orig 2002-01-24 08:38:58 +0100
  155. +++ src/psgen.c 2005-02-05 09:50:45 +0100
  156. @@ -2034,8 +2034,9 @@
  157. else
  158. {
  159. ftail++;
  160. - strncpy (buf, fname, ftail - fname);
  161. - buf[ftail - fname] = '\0';
  162. + i = ftail - fname >= sizeof (buf)-1 ? sizeof (buf)-1 : ftail - fname;
  163. + strncpy (buf, fname, i);
  164. + buf[i] = '\0';
  165. }
  166. if (nup > 1)
  167. @@ -2385,9 +2386,10 @@
  168. MESSAGE (2, (stderr, "^@epsf=\"%s\"\n", token->u.epsf.filename));
  169. i = strlen (token->u.epsf.filename);
  170. + /*
  171. if (i > 0 && token->u.epsf.filename[i - 1] == '|')
  172. {
  173. - /* Read EPS data from pipe. */
  174. + / * Read EPS data from pipe. * /
  175. token->u.epsf.pipe = 1;
  176. token->u.epsf.filename[i - 1] = '\0';
  177. token->u.epsf.fp = popen (token->u.epsf.filename, "r");
  178. @@ -2400,6 +2402,7 @@
  179. }
  180. }
  181. else
  182. + */
  183. {
  184. char *filename;
  185. @@ -2581,7 +2584,7 @@
  186. read_float (InputStream *is, int units, int horizontal)
  187. {
  188. char buf[256];
  189. - int i, ch;
  190. + int i, ch = 0;
  191. double val;
  192. for (i = 0; (i < sizeof (buf) - 1
  193. Index: src/util.c
  194. --- src/util.c.orig 1999-09-17 17:26:51 +0200
  195. +++ src/util.c 2005-02-05 09:59:00 +0100
  196. @@ -1239,6 +1239,8 @@
  197. /* Create result. */
  198. cp = xmalloc (len + 1);
  199. + if (cp == NULL)
  200. + return NULL;
  201. for (i = 0, j = 0; string[i]; i++)
  202. switch (string[i])
  203. {
  204. @@ -1879,6 +1881,7 @@
  205. char *cmd = NULL;
  206. int cmdlen;
  207. int i, pos;
  208. + char *cp;
  209. is->is_pipe = 1;
  210. @@ -1902,12 +1905,16 @@
  211. {
  212. case 's':
  213. /* Expand cmd-buffer. */
  214. - cmdlen += strlen (fname);
  215. - cmd = xrealloc (cmd, cmdlen);
  216. + if ((cp = shell_escape (fname)) != NULL)
  217. + {
  218. + cmdlen += strlen (cp);
  219. + cmd = xrealloc (cmd, cmdlen);
  220. - /* Paste filename. */
  221. - strcpy (cmd + pos, fname);
  222. - pos += strlen (fname);
  223. + /* Paste filename. */
  224. + strcpy (cmd + pos, cp);
  225. + pos += strlen (cp);
  226. + free (cp);
  227. + }
  228. i++;
  229. break;
  230. @@ -1991,12 +1998,13 @@
  231. if (is->bufpos >= is->data_in_buf)
  232. {
  233. /* At the EOF? */
  234. - if (is->nreads > 0 && is->data_in_buf < sizeof (is->buf))
  235. + if (is->nreads > 0 && is->data_in_buf < sizeof (is->buf)-1)
  236. /* Yes. */
  237. return EOF;
  238. /* Read more data. */
  239. - is->data_in_buf = fread (is->buf, 1, sizeof (is->buf), is->fp);
  240. + memset (is->buf, 0, sizeof (is->buf));
  241. + is->data_in_buf = fread (is->buf, 1, sizeof (is->buf)-1, is->fp);
  242. is->bufpos = 0;
  243. is->nreads++;
  244. @@ -2116,3 +2124,36 @@
  245. {
  246. return buffer->len;
  247. }
  248. +
  249. +/*
  250. + * Escapes the name of a file so that the shell groks it in 'single'
  251. + * quotation marks. The resulting pointer has to be free()ed when not
  252. + * longer used.
  253. +*/
  254. +char *
  255. +shell_escape(const char *fn)
  256. +{
  257. + size_t len = 0;
  258. + const char *inp;
  259. + char *retval, *outp;
  260. +
  261. + for(inp = fn; *inp; ++inp)
  262. + switch(*inp)
  263. + {
  264. + case '\'': len += 4; break;
  265. + default: len += 1; break;
  266. + }
  267. +
  268. + outp = retval = malloc(len + 1);
  269. + if(!outp)
  270. + return NULL; /* perhaps one should do better error handling here */
  271. + for(inp = fn; *inp; ++inp)
  272. + switch(*inp)
  273. + {
  274. + case '\'': *outp++ = '\''; *outp++ = '\\'; *outp++ = '\'', *outp++ = '\''; break;
  275. + default: *outp++ = *inp; break;
  276. + }
  277. + *outp = 0;
  278. +
  279. + return retval;
  280. +}
  281. Index: states/main.c
  282. --- states/main.c.orig 2000-11-30 07:40:17 +0100
  283. +++ states/main.c 2005-02-05 09:50:45 +0100
  284. @@ -202,6 +202,7 @@
  285. #if HAVE_SETLOCALE
  286. #if HAVE_LC_MESSAGES
  287. setlocale (LC_MESSAGES, "");
  288. + setlocale (LC_CTYPE, "");
  289. #endif
  290. #endif
  291. #if ENABLE_NLS
  292. Index: states/over.in
  293. --- states/over.in.orig 1997-03-19 11:24:49 +0100
  294. +++ states/over.in 2005-02-05 09:50:45 +0100
  295. @@ -2,4 +2,4 @@
  296. librarydir=@LIBRARYDIR@
  297. -enscript -E -p- --quiet --language=overstrike $* 2>&1 | less
  298. +enscript -E -p- --quiet --language=overstrike "$@" 2>&1 | sensible-pager
  299. Index: afm/Makefile.in
  300. --- afm/Makefile.in.orig 2002-01-24 08:39:24 +0100
  301. +++ afm/Makefile.in 2005-02-05 10:04:31 +0100
  302. @@ -227,10 +227,10 @@
  303. install-data-local:
  304. - $(top_srcdir)/mkinstalldirs $(datadir)/enscript
  305. - $(top_srcdir)/mkinstalldirs $(datadir)/enscript/afm
  306. + $(top_srcdir)/mkinstalldirs $(DESTDIR)$(datadir)/enscript
  307. + $(top_srcdir)/mkinstalldirs $(DESTDIR)$(datadir)/enscript/afm
  308. for f in $(EXTRA_DIST); do \
  309. - $(INSTALL_DATA) $(srcdir)/$$f $(datadir)/enscript/afm/$$f; \
  310. + $(INSTALL_DATA) $(srcdir)/$$f $(DESTDIR)$(datadir)/enscript/afm/$$f; \
  311. done
  312. uninstall-local:
  313. Index: lib/Makefile.in
  314. --- lib/Makefile.in.orig 2002-01-24 08:39:27 +0100
  315. +++ lib/Makefile.in 2005-02-05 10:07:31 +0100
  316. @@ -254,15 +254,15 @@
  317. all-local: enscript.cfg
  318. install-data-local: enscript.cfg
  319. - $(top_srcdir)/mkinstalldirs $(sysconfdir)
  320. - if test -r $(sysconfdir)/enscript.cfg; then \
  321. - cp $(sysconfdir)/enscript.cfg $(sysconfdir)/enscript.cfg.old; \
  322. + $(top_srcdir)/mkinstalldirs $(DESTDIR)$(sysconfdir)
  323. + if test -r $(DESTDIR)$(sysconfdir)/enscript.cfg; then \
  324. + cp $(DESTDIR)$(sysconfdir)/enscript.cfg $(DESTDIR)$(sysconfdir)/enscript.cfg.old; \
  325. else :; \
  326. fi
  327. - $(INSTALL_DATA) enscript.cfg $(sysconfdir)/enscript.cfg
  328. + $(INSTALL_DATA) enscript.cfg $(DESTDIR)$(sysconfdir)/enscript.cfg
  329. uninstall-local:
  330. - rm -f $(sysconfdir)/enscript.cfg
  331. + rm -f $(DESTDIR)$(sysconfdir)/enscript.cfg
  332. enscript.cfg: $(srcdir)/enscript.cfg.in Makefile
  333. sed 's%@DATADIR@%$(datadir)%g; s%@media@%@MEDIA@%g; s%@BINDIR@%$(bindir)%g; s%@spooler@%@SPOOLER@%g; s%@pslevel@%@PSLEVEL@%g; s%@queueparam@%@QUEUEPARAM@%g' \
  334. Index: states/hl/Makefile.in
  335. --- states/hl/Makefile.in.orig 2002-01-24 08:39:40 +0100
  336. +++ states/hl/Makefile.in 2005-02-05 14:17:13 +0100
  337. @@ -234,14 +234,14 @@
  338. install-data-local:
  339. - $(top_srcdir)/mkinstalldirs $(datadir)/enscript
  340. - $(top_srcdir)/mkinstalldirs $(datadir)/enscript/hl
  341. + $(top_srcdir)/mkinstalldirs $(DESTDIR)$(datadir)/enscript
  342. + $(top_srcdir)/mkinstalldirs $(DESTDIR)$(datadir)/enscript/hl
  343. for f in $(states); do \
  344. - $(INSTALL_DATA) $(srcdir)/$$f $(datadir)/enscript/hl/$$f; \
  345. + $(INSTALL_DATA) $(srcdir)/$$f $(DESTDIR)$(datadir)/enscript/hl/$$f; \
  346. done
  347. uninstall-local:
  348. - rm -rf $(datadir)/enscript/hl
  349. + rm -rf $(DESTDIR)$(datadir)/enscript/hl
  350. # Tell versions [3.59,3.63) of GNU make to not export all variables.
  351. # Otherwise a system limit (for SysV at least) may be exceeded.