1
0

010-fix_message-header.patch 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. --- a/ssmtp.c
  2. +++ b/ssmtp.c
  3. @@ -282,6 +282,7 @@ standardise() -- Trim off '\n's and doub
  4. */
  5. bool_t standardise(char *str, bool_t *linestart)
  6. {
  7. + size_t sl;
  8. char *p;
  9. bool_t leadingdot = False;
  10. @@ -297,6 +298,12 @@ bool_t standardise(char *str, bool_t *li
  11. if((p = strchr(str, '\n'))) {
  12. *p = '\0';
  13. *linestart = True;
  14. +
  15. + /* If the line ended in "\r\n", then drop the '\r' too */
  16. + sl = strlen(str);
  17. + if(sl >= 1 && str[sl - 1] == '\r') {
  18. + str[sl - 1] = '\0';
  19. + }
  20. }
  21. return(leadingdot);
  22. }
  23. @@ -690,6 +697,14 @@ void header_parse(FILE *stream)
  24. }
  25. len++;
  26. + if(l == '\r' && c == '\n') {
  27. + /* Properly handle input that already has "\r\n"
  28. + line endings; see https://bugs.debian.org/584162 */
  29. + l = (len >= 2 ? *(q - 2) : '\n');
  30. + q--;
  31. + len--;
  32. + }
  33. +
  34. if(l == '\n') {
  35. switch(c) {
  36. case ' ':
  37. @@ -712,8 +727,9 @@ void header_parse(FILE *stream)
  38. if((q = strrchr(p, '\n'))) {
  39. *q = '\0';
  40. }
  41. - header_save(p);
  42. -
  43. + if(len > 0) {
  44. + header_save(p);
  45. + }
  46. q = p;
  47. len = 0;
  48. }
  49. @@ -722,35 +738,12 @@ void header_parse(FILE *stream)
  50. l = c;
  51. }
  52. - if(in_header) {
  53. - if(l == '\n') {
  54. - switch(c) {
  55. - case ' ':
  56. - case '\t':
  57. - /* Must insert '\r' before '\n's embedded in header
  58. - fields otherwise qmail won't accept our mail
  59. - because a bare '\n' violates some RFC */
  60. -
  61. - *(q - 1) = '\r'; /* Replace previous \n with \r */
  62. - *q++ = '\n'; /* Insert \n */
  63. - len++;
  64. -
  65. - break;
  66. -
  67. - case '\n':
  68. - in_header = False;
  69. -
  70. - default:
  71. - *q = '\0';
  72. - if((q = strrchr(p, '\n'))) {
  73. - *q = '\0';
  74. - }
  75. - header_save(p);
  76. -
  77. - q = p;
  78. - len = 0;
  79. - }
  80. - }
  81. + if(in_header && l == '\n') {
  82. + /* Got EOF while reading the header */
  83. + if((q = strrchr(p, '\n'))) {
  84. + *q = '\0';
  85. + }
  86. + header_save(p);
  87. }
  88. (void)free(p);
  89. }