enscript-1.6.3-security.patch 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. diff -u -p -Nr --exclude CVS orig/enscript-1.6.3/src/gsint.h enscript-1.6.3.CAN-2004-1184/src/gsint.h
  2. --- orig/enscript-1.6.3/src/gsint.h 2000-07-11 17:28:06.000000000 +0200
  3. +++ enscript-1.6.3.CAN-2004-1184/src/gsint.h 2005-01-04 20:45:24.000000000 +0100
  4. @@ -701,4 +701,9 @@ FILE *printer_open ___P ((char *cmd, cha
  5. */
  6. void printer_close ___P ((void *context));
  7. +/*
  8. + * Escape filenames for shell usage
  9. + */
  10. +char *shell_escape ___P ((const char *fn));
  11. +
  12. #endif /* not GSINT_H */
  13. diff -u -p -Nr --exclude CVS orig/enscript-1.6.3/src/main.c enscript-1.6.3.CAN-2004-1184/src/main.c
  14. --- orig/enscript-1.6.3/src/main.c 2005-01-04 20:52:31.000000000 +0100
  15. +++ enscript-1.6.3.CAN-2004-1184/src/main.c 2005-01-05 10:57:44.000000000 +0100
  16. @@ -1555,9 +1555,13 @@ name width\theight\tllx\tlly
  17. buffer_append (&cmd, intbuf);
  18. buffer_append (&cmd, " ");
  19. - buffer_append (&cmd, "-Ddocument_title=\"");
  20. - buffer_append (&cmd, title);
  21. - buffer_append (&cmd, "\" ");
  22. + buffer_append (&cmd, "-Ddocument_title=\'");
  23. + if ((cp = shell_escape (title)) != NULL)
  24. + {
  25. + buffer_append (&cmd, cp);
  26. + free (cp);
  27. + }
  28. + buffer_append (&cmd, "\' ");
  29. buffer_append (&cmd, "-Dtoc=");
  30. buffer_append (&cmd, toc ? "1" : "0");
  31. @@ -1574,8 +1578,14 @@ name width\theight\tllx\tlly
  32. /* Append input files. */
  33. for (i = optind; i < argc; i++)
  34. {
  35. - buffer_append (&cmd, " ");
  36. - buffer_append (&cmd, argv[i]);
  37. + char *cp;
  38. + if ((cp = shell_escape (argv[i])) != NULL)
  39. + {
  40. + buffer_append (&cmd, " \'");
  41. + buffer_append (&cmd, cp);
  42. + buffer_append (&cmd, "\'");
  43. + free (cp);
  44. + }
  45. }
  46. /* And do the job. */
  47. @@ -1636,7 +1645,7 @@ name width\theight\tllx\tlly
  48. buffer_ptr (opts), buffer_len (opts));
  49. }
  50. - buffer_append (&buffer, " \"%s\"");
  51. + buffer_append (&buffer, " \'%s\'");
  52. input_filter = buffer_copy (&buffer);
  53. input_filter_stdin = "-";
  54. diff -u -p -Nr --exclude CVS orig/enscript-1.6.3/src/util.c enscript-1.6.3.CAN-2004-1184/src/util.c
  55. --- orig/enscript-1.6.3/src/util.c 1999-09-17 17:26:51.000000000 +0200
  56. +++ enscript-1.6.3.CAN-2004-1184/src/util.c 2005-01-05 10:43:23.000000000 +0100
  57. @@ -1239,6 +1239,8 @@ escape_string (char *string)
  58. /* Create result. */
  59. cp = xmalloc (len + 1);
  60. + if (cp == NULL)
  61. + return NULL;
  62. for (i = 0, j = 0; string[i]; i++)
  63. switch (string[i])
  64. {
  65. @@ -1879,6 +1881,7 @@ is_open (InputStream *is, FILE *fp, char
  66. char *cmd = NULL;
  67. int cmdlen;
  68. int i, pos;
  69. + char *cp;
  70. is->is_pipe = 1;
  71. @@ -1902,12 +1905,16 @@ is_open (InputStream *is, FILE *fp, char
  72. {
  73. case 's':
  74. /* Expand cmd-buffer. */
  75. - cmdlen += strlen (fname);
  76. - cmd = xrealloc (cmd, cmdlen);
  77. + if ((cp = shell_escape (fname)) != NULL)
  78. + {
  79. + cmdlen += strlen (cp);
  80. + cmd = xrealloc (cmd, cmdlen);
  81. - /* Paste filename. */
  82. - strcpy (cmd + pos, fname);
  83. - pos += strlen (fname);
  84. + /* Paste filename. */
  85. + strcpy (cmd + pos, cp);
  86. + pos += strlen (cp);
  87. + free (cp);
  88. + }
  89. i++;
  90. break;
  91. @@ -2116,3 +2123,36 @@ buffer_len (Buffer *buffer)
  92. {
  93. return buffer->len;
  94. }
  95. +
  96. +/*
  97. + * Escapes the name of a file so that the shell groks it in 'single'
  98. + * quotation marks. The resulting pointer has to be free()ed when not
  99. + * longer used.
  100. +*/
  101. +char *
  102. +shell_escape(const char *fn)
  103. +{
  104. + size_t len = 0;
  105. + const char *inp;
  106. + char *retval, *outp;
  107. +
  108. + for(inp = fn; *inp; ++inp)
  109. + switch(*inp)
  110. + {
  111. + case '\'': len += 4; break;
  112. + default: len += 1; break;
  113. + }
  114. +
  115. + outp = retval = malloc(len + 1);
  116. + if(!outp)
  117. + return NULL; /* perhaps one should do better error handling here */
  118. + for(inp = fn; *inp; ++inp)
  119. + switch(*inp)
  120. + {
  121. + case '\'': *outp++ = '\''; *outp++ = '\\'; *outp++ = '\'', *outp++ = '\''; break;
  122. + default: *outp++ = *inp; break;
  123. + }
  124. + *outp = 0;
  125. +
  126. + return retval;
  127. +}
  128. diff -u -p -Nr --exclude CVS enscript-1.6.3.CAN-2004-1184/src/psgen.c enscript-1.6.3.CAN-2004-1185/src/psgen.c
  129. --- enscript-1.6.3.CAN-2004-1184/src/psgen.c 2005-01-04 20:59:56.000000000 +0100
  130. +++ enscript-1.6.3.CAN-2004-1185/src/psgen.c 2005-01-05 15:22:40.000000000 +0100
  131. @@ -2385,9 +2385,10 @@ recognize_eps_file (Token *token)
  132. MESSAGE (2, (stderr, "^@epsf=\"%s\"\n", token->u.epsf.filename));
  133. i = strlen (token->u.epsf.filename);
  134. + /*
  135. if (i > 0 && token->u.epsf.filename[i - 1] == '|')
  136. {
  137. - /* Read EPS data from pipe. */
  138. + / * Read EPS data from pipe. * /
  139. token->u.epsf.pipe = 1;
  140. token->u.epsf.filename[i - 1] = '\0';
  141. token->u.epsf.fp = popen (token->u.epsf.filename, "r");
  142. @@ -2400,6 +2401,7 @@ recognize_eps_file (Token *token)
  143. }
  144. }
  145. else
  146. + */
  147. {
  148. char *filename;
  149. diff -u -p -Nr --exclude CVS enscript-1.6.3.CAN-2004-1185/src/psgen.c enscript-1.6.3.CAN-2004-1186/src/psgen.c
  150. --- enscript-1.6.3.CAN-2004-1185/src/psgen.c 2005-01-05 15:22:40.000000000 +0100
  151. +++ enscript-1.6.3.CAN-2004-1186/src/psgen.c 2005-01-05 15:22:44.000000000 +0100
  152. @@ -2034,8 +2034,9 @@ dump_ps_page_header (char *fname, int em
  153. else
  154. {
  155. ftail++;
  156. - strncpy (buf, fname, ftail - fname);
  157. - buf[ftail - fname] = '\0';
  158. + i = ftail - fname >= sizeof (buf)-1 ? sizeof (buf)-1 : ftail - fname;
  159. + strncpy (buf, fname, i);
  160. + buf[i] = '\0';
  161. }
  162. if (nup > 1)