-
Notifications
You must be signed in to change notification settings - Fork 2
/
qmail-smtpd-linefeed.patch
78 lines (75 loc) · 2.82 KB
/
qmail-smtpd-linefeed.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
--- qmail-smtpd.c 2007-02-09 22:32:52.000000000 +0100
+++ ../qmail-1.03.lfpatched/qmail-smtpd.c 2007-02-09 22:14:02.000000000 +0100
@@ -107,7 +107,6 @@
void die_nomem() { out("421 out of memory (#4.3.0)\r\n"); flush(); _exit(1); }
void die_control() { out("421 unable to read controls (#4.3.0)\r\n"); flush(); _exit(1); }
void die_ipme() { out("421 unable to figure out my IP addresses (#4.3.0)\r\n"); flush(); _exit(1); }
-void straynewline() { out("451 See http://pobox.com/~djb/docs/smtplf.html.\r\n"); flush(); _exit(1); }
void die_cannot_auth() { out("421 REQUIRE_AUTH set without valid AUTH program.\r\n"); flush(); _exit(1); }
@@ -767,7 +766,8 @@
int flagmaybey; /* 1 if this line might match \r\n, if fih */
int flagmaybez; /* 1 if this line might match DELIVERED, if fih */
- state = 1;
+ /* NEWLINE: We start in state 2 now, instead of state 1. */
+ state = 2;
*hops = 0;
flaginheader = 1;
pos = 0; flagmaybex = flagmaybey = flagmaybez = 1;
@@ -782,36 +782,42 @@
if (flagmaybex) if (pos == 7) ++*hops;
if (pos < 2) if (ch != "\r\n"[pos]) flagmaybey = 0;
if (flagmaybey) if (pos == 1) flaginheader = 0;
+ /* NEWLINE: Header may end on \n now, too. */
+ if (pos == 0) if (ch == '\n') flaginheader = 0;
++pos;
}
if (ch == '\n') { pos = 0; flagmaybex = flagmaybey = flagmaybez = 1; }
}
switch(state) {
+ /* NEWLINE: New state machine to allow both \n and \r\n */
case 0:
- if (ch == '\n') straynewline();
- if (ch == '\r') { state = 4; continue; }
+ if (ch == '\n') state = 2;
+ if (ch == '\r') { state = 1; continue; }
break;
- case 1: /* \r\n */
- if (ch == '\n') straynewline();
- if (ch == '.') { state = 2; continue; }
- if (ch == '\r') { state = 4; continue; }
+ case 1: /* \r */
+ if (ch == '\n') { state = 2; break; }
+ if (ch == '\r') break;
state = 0;
+ put ("\r");
break;
- case 2: /* \r\n + . */
- if (ch == '\n') straynewline();
- if (ch == '\r') { state = 3; continue; }
+ case 2: /* \n or \r\n */
+ if (ch == '.') { state = 3; continue; }
+ if (ch == '\r') { state = 1; continue; }
+ if (ch == '\n') break;
state = 0;
break;
- case 3: /* \r\n + .\r */
+ case 3: /* \n or \r\n . */
if (ch == '\n') return;
- put(".");
- put("\r");
if (ch == '\r') { state = 4; continue; }
state = 0;
break;
- case 4: /* + \r */
- if (ch == '\n') { state = 1; break; }
- if (ch != '\r') { put("\r"); state = 0; }
+ case 4: /* \n or \r\n . \r */
+ if (ch == '\n') return;
+ put (".");
+ put ("\r");
+ if (ch == '\r') { state = 1; continue; }
+ state = 0;
+ break;
}
put(&ch);
}