a2ps.patch 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. Index: lib/quotearg.c
  2. --- lib/quotearg.c.orig 2000-01-19 09:19:48 +0100
  3. +++ lib/quotearg.c 2004-08-06 13:34:41 +0200
  4. @@ -59,6 +59,9 @@
  5. #endif
  6. #if HAVE_MBRTOWC && HAVE_WCHAR_H
  7. +#if defined(__hpux)
  8. +# include<sys/_mbstate_t.h>
  9. +#endif
  10. # include <wchar.h>
  11. #else
  12. # define iswprint(wc) 1
  13. Index: lib/strftime.c
  14. --- lib/strftime.c.orig 2000-01-02 08:10:09 +0100
  15. +++ lib/strftime.c 2004-08-06 13:35:34 +0200
  16. @@ -67,6 +67,9 @@
  17. #if DO_MULTIBYTE
  18. # if HAVE_MBRLEN
  19. +# if defined(__hpux)
  20. +# include<sys/_mbstate_t.h>
  21. +# endif
  22. # include <wchar.h>
  23. # else
  24. /* Simulate mbrlen with mblen as best we can. */
  25. Index: lib/path-concat.c
  26. --- lib/path-concat.c.orig 1999-10-10 20:34:46 +0200
  27. +++ lib/path-concat.c 2004-08-18 19:56:40 +0200
  28. @@ -31,8 +31,6 @@
  29. #endif
  30. #include <sys/types.h>
  31. -char *malloc ();
  32. -
  33. #ifndef DIRECTORY_SEPARATOR
  34. # define DIRECTORY_SEPARATOR '/'
  35. #endif
  36. http://cve.mitre.org/cgi-bin/cvename.cgi?name=CAN-2004-1170
  37. a2ps 4.13 allows remote attackers to execute arbitrary commands via
  38. shell metacharacters in the filename.
  39. source: http://www.freebsd.org/cgi/cvsweb.cgi/~checkout~/ports/print/a2ps-letter/files/patch-select.c?rev=1.1&content-type=text/plain
  40. --- src/select.c.orig Thu Dec 16 02:04:56 1999
  41. +++ src/select.c Sat Aug 21 12:05:31 2004
  42. @@ -131,6 +131,36 @@
  43. return 1;
  44. }
  45. +/* escapes the name of a file so that the shell groks it in 'single' q.marks.
  46. + The resulting pointer has to be free()ed when not longer used. */
  47. +char *
  48. +shell_escape(const char *fn)
  49. +{
  50. + size_t len = 0;
  51. + const char *inp;
  52. + char *retval, *outp;
  53. +
  54. + for(inp = fn; *inp; ++inp)
  55. + switch(*inp)
  56. + {
  57. + case '\'': len += 4; break;
  58. + default: len += 1; break;
  59. + }
  60. +
  61. + outp = retval = malloc(len + 1);
  62. + if(!outp)
  63. + return NULL; /* perhaps one should do better error handling here */
  64. + for(inp = fn; *inp; ++inp)
  65. + switch(*inp)
  66. + {
  67. + case '\'': *outp++ = '\''; *outp++ = '\\'; *outp++ = '\'', *outp++ = '\''; break;
  68. + default: *outp++ = *inp; break;
  69. + }
  70. + *outp = 0;
  71. +
  72. + return retval;
  73. +}
  74. +
  75. /* What says file about the type of a file (result is malloc'd). NULL
  76. if could not be run. */
  77. @@ -144,11 +174,15 @@
  78. if (IS_EMPTY (job->file_command))
  79. return NULL;
  80. + filename = shell_escape(filename);
  81. + if(filename == NULL)
  82. + return NULL;
  83. /* Call file(1) with the correct option */
  84. - command = ALLOCA (char, (2
  85. + command = ALLOCA (char, (4
  86. + strlen (job->file_command)
  87. + ustrlen (filename)));
  88. - sprintf (command, "%s %s", job->file_command, (const char *) filename);
  89. + sprintf (command, "%s '%s'", job->file_command, (const char *) filename);
  90. + free(filename);
  91. message (msg_tool, (stderr, "Reading pipe: `%s'\n", command));
  92. file_out = popen (command, "r");