patch-src_metamail_metamail_c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. $OpenBSD: patch-src_metamail_metamail_c,v 1.4 2017/05/25 17:47:08 espie Exp $
  2. Index: src/metamail/metamail.c
  3. --- src/metamail/metamail.c.orig
  4. +++ src/metamail/metamail.c
  5. @@ -20,6 +20,9 @@ WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
  6. ******************************************************* */
  7. #include <stdio.h>
  8. +#include <stdlib.h>
  9. +#include <unistd.h>
  10. +#include <string.h>
  11. #include <ctype.h>
  12. #include <sys/types.h>
  13. #include <sys/stat.h>
  14. @@ -29,7 +32,7 @@ WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
  15. #ifdef BORLAND
  16. #define F_OK 0
  17. extern unsigned _stklen = 16384;
  18. -extern char *mktemp(char *);
  19. +extern char *mkstemp(char *);
  20. #define WRITE_BINARY "w"
  21. #else /* BORLAND */
  22. #ifdef MICROSOFT
  23. @@ -46,12 +49,14 @@ extern char *mktemp(char *);
  24. #include <signal.h>
  25. #ifndef AMIGA
  26. -#ifdef SYSV
  27. +#if defined(HAVE_TCGETATTR)
  28. +#include <termios.h>
  29. +#elif defined(SYSV)
  30. #include <termio.h>
  31. #include <unistd.h>
  32. -#else /* SYSV */
  33. +#else
  34. #include <sgtty.h>
  35. -#endif /* SYSV */
  36. +#endif
  37. #endif /* AMIGA */
  38. #endif /* MICROSOFT */
  39. #endif /* BORLAND */
  40. @@ -100,15 +105,12 @@ extern char **environ, *gets();
  41. #define CMDSIZE 1200 /* Maximum size of command to execute */
  42. #define LINE_BUF_SIZE 2000
  43. -#ifndef MICROSOFT
  44. -extern char *malloc();
  45. -extern char *realloc();
  46. -#endif
  47. -extern char *getenv();
  48. -extern char *index();
  49. -extern char *rindex();
  50. char fileToDelete[MAX_FILE_NAME_SIZE];
  51. +void maybephead(char *);
  52. +void PauseForUser(void);
  53. +
  54. +char *hdr;
  55. char *FindParam();
  56. extern FILE *popen();
  57. static char *nomem = "Out of memory!";
  58. @@ -302,24 +304,6 @@ char **argv;
  59. int retcode;
  60. modpath(AUXPATH);
  61. -#ifndef MSDOS
  62. - signal(SIGINT, cleanup);
  63. -#ifndef AMIGA
  64. - signal(SIGILL, cleanup);
  65. - signal(SIGTRAP, cleanup);
  66. - signal(SIGIOT, cleanup);
  67. - signal(SIGFPE, cleanup);
  68. -#ifndef LINUX
  69. - signal(SIGEMT, cleanup);
  70. - signal(SIGBUS, cleanup);
  71. -#endif
  72. - signal(SIGSEGV, cleanup);
  73. - signal(SIGTERM, cleanup);
  74. -#endif
  75. -#endif
  76. -#ifdef SIGXCPU
  77. - signal(SIGXCPU, cleanup);
  78. -#endif
  79. tmproot = getenv("METAMAIL_TMPDIR");
  80. if (!tmproot) tmproot="/tmp";
  81. mailheaders = getenv("MM_HEADERS");
  82. @@ -579,7 +563,7 @@ int nestingdepth;
  83. int overwriteans = -1;
  84. do {
  85. printf("File %s exists. Do you want to overwrite it (y/n) ?\n", Fname);
  86. - s = gets(AnsBuf);
  87. + s = fgets(AnsBuf, sizeof(AnsBuf), stdin);
  88. if (!s) {
  89. overwriteans = 0;
  90. } else {
  91. @@ -1202,9 +1186,9 @@ char *SquirrelFile;
  92. fprintf(outfp, "Content-type: %s", ContentType);
  93. for (j=0; j<CParamsUsed; ++j) {
  94. fprintf(outfp, " ; ");
  95. - fprintf(outfp, CParams[j]);
  96. + fprintf(outfp, "%s", CParams[j]);
  97. fprintf(outfp, " = ");
  98. - fprintf(outfp, CParamValues[j]);
  99. + fprintf(outfp, "%s", CParamValues[j]);
  100. }
  101. fprintf(outfp, "\n\n");
  102. TranslateInputToOutput(InputFP, outfp, EncodingCode, ContentType);
  103. @@ -1823,7 +1807,7 @@ char *ctype, *progname, *label;
  104. } else {
  105. printf("This message contains '%s'-format data.\nDo you want to view it using the '%s' command (y/n) [y] ? ", ctype, ShortCommand(progname));
  106. }
  107. - s = gets(AnsBuf);
  108. + s = fgets(AnsBuf, sizeof(AnsBuf), stdin);
  109. if (!s) return(0); /* EOF */
  110. while (s && *s && isspace((unsigned char) *s)) ++s;
  111. if (*s == 'y' || *s == 'Y' || !*s || *s == '\n') return(1);
  112. @@ -1900,6 +1884,7 @@ char *hdr;
  113. }
  114. /* check the header given to see if it matches any in the KeyHeadList */
  115. +void
  116. maybephead(hdr)
  117. char *hdr;
  118. {
  119. @@ -2022,7 +2007,7 @@ int ShowLeadingWhitespace;
  120. if (lc2strcmp(charset, PrevCharset)) {
  121. char *s2, *charsetinuse;
  122. - strcpy(PrevCharset, charset);
  123. + strlcpy(PrevCharset, charset, sizeof(PrevCharset));
  124. for (s2=PrevCharset; *s2; ++s2) {
  125. if (isupper((unsigned char) *s2)) *s2 = tolower((unsigned char) *s2);
  126. }
  127. @@ -2032,7 +2017,7 @@ int ShowLeadingWhitespace;
  128. }
  129. }
  130. if (ecode == ENCODING_NONE) {
  131. - printf(txt+1);
  132. + printf("%s", txt+1);
  133. } else {
  134. /* What follows is REALLY bogus, but all my encoding stuff is pipe-oriented right now... */
  135. MkTmpFileName(TmpFile);
  136. @@ -2374,8 +2359,11 @@ char *Prefix;
  137. }
  138. int HasSavedTtyState=0;
  139. +
  140. #if !defined(AMIGA) && !defined(MSDOS)
  141. -#ifdef SYSV
  142. +#if defined(HAVE_TCGETATTR)
  143. +static struct termios MyTtyStateIn, MyTtyStateOut;
  144. +#elif defined(SYSV)
  145. static struct termio MyTtyStateIn, MyTtyStateOut;
  146. #else
  147. static struct sgttyb MyTtyStateIn, MyTtyStateOut;
  148. @@ -2385,7 +2373,10 @@ static struct sgttyb MyTtyStateIn, MyTtyStateOut;
  149. SaveTtyState() {
  150. /* Bogus -- would like a good portable way to reset the terminal state here */
  151. #if !defined(AMIGA) && !defined(MSDOS)
  152. -#ifdef SYSV
  153. +#if defined(HAVE_TCGETATTR)
  154. + tcgetattr(fileno(stdin), &MyTtyStateIn);
  155. + tcgetattr(fileno(stdout), &MyTtyStateOut);
  156. +#elif defined(SYSV)
  157. ioctl(fileno(stdin), TCGETA, &MyTtyStateIn);
  158. ioctl(fileno(stdout), TCGETA, &MyTtyStateOut);
  159. #else
  160. @@ -2398,8 +2389,13 @@ SaveTtyState() {
  161. RestoreTtyState() {
  162. #if !defined(AMIGA) && !defined(MSDOS)
  163. -#ifdef SYSV
  164. +#if defined(HAVE_TCGETATTR)
  165. if (HasSavedTtyState) {
  166. + tcsetattr(fileno(stdin), TCSANOW, &MyTtyStateIn);
  167. + tcsetattr(fileno(stdout), TCSANOW, &MyTtyStateOut);
  168. + }
  169. +#elif defined(SYSV)
  170. + if (HasSavedTtyState) {
  171. ioctl(fileno(stdout), TCSETA, &MyTtyStateOut);
  172. ioctl(fileno(stdin), TCSETA, &MyTtyStateIn);
  173. }
  174. @@ -2489,14 +2485,14 @@ char *name;
  175. {
  176. #ifdef AMIGA
  177. strcpy(name, "T:mmXXXXXX");
  178. - mktemp(name);
  179. + close(mkstemp(name));
  180. #else
  181. #ifndef MSDOS
  182. sprintf(name, "%s/mm.XXXXXX", tmproot);
  183. - mktemp(name);
  184. + close(mkstemp(name));
  185. #else
  186. strcpy(name, "TXXXXXX");
  187. - if (!mktemp(name))
  188. + if (!close(mkstemp(name)))
  189. name[0] = 0;
  190. else
  191. if (DoDebug) printf("temp name = \"%s\"\n", name);
  192. @@ -2655,6 +2651,7 @@ char *s2;
  193. #endif
  194. }
  195. +void
  196. PauseForUser() {
  197. #if defined(MSDOS) || defined(AMIGA)
  198. char Buf[100];
  199. @@ -2681,7 +2678,16 @@ PauseForUser() {
  200. StartRawStdin() {
  201. #if !defined(AMIGA) && !defined(MSDOS)
  202. -#ifdef SYSV
  203. +#if defined(HAVE_TCGETATTR)
  204. + struct termios term;
  205. +
  206. + if (tcgetattr(0, &term) == -1) /* get current (i.e. cooked) termio */
  207. + return -1;
  208. + term.c_lflag &= ~ICANON; /* clear ICANON giving raw mode */
  209. + term.c_cc[VMIN] = 1; /* set MIN char count to 1 */
  210. + term.c_cc[VTIME] = 0; /* set NO time limit */
  211. + return tcsetattr(0, TCSADRAIN, &term);
  212. +#elif defined(SYSV)
  213. struct termio orterm, fterm;
  214. ioctl(0, TCGETA, &orterm); /* get current (i.e. cooked) termio */
  215. fterm = orterm; /* get termio to modify */