Line 0
Link Here
|
|
|
1 |
From http://www.packetstormsecurity.org/0411-advisories/up-imapproxy.txt |
2 |
|
3 |
diff -ru up-imapproxy-1.2.2/include/imapproxy.h up-imapproxy-1.2.2-fixed/include/imapproxy.h |
4 |
--- include/imapproxy.h 2004-07-23 16:17:24.000000000 +0300 |
5 |
+++ include/imapproxy.h.orig 2004-11-07 18:51:00.000000000 +0200 |
6 |
@@ -206,7 +206,7 @@ |
7 |
char ReadBuf[ BUFSIZE ]; /* Read Buffer */ |
8 |
unsigned int BytesInReadBuffer; /* bytes left in read buffer */ |
9 |
unsigned int ReadBytesProcessed; /* bytes already processed in read buf */ |
10 |
- long LiteralBytesRemaining; /* num of bytes left to read as literal */ |
11 |
+ unsigned long LiteralBytesRemaining;/* num of bytes left to read as literal */ |
12 |
unsigned char NonSyncLiteral; /* rfc2088 alert flag */ |
13 |
unsigned char MoreData; /* flag to tell caller "more data" */ |
14 |
unsigned char TraceOn; /* trace this transaction? */ |
15 |
@@ -304,7 +304,7 @@ |
16 |
*/ |
17 |
extern int IMAP_Write( ICD_Struct *, const void *, int ); |
18 |
extern int IMAP_Read( ICD_Struct *, void *, int ); |
19 |
-extern int IMAP_Line_Read( ITD_Struct * ); |
20 |
+extern int IMAP_Line_Read( ITD_Struct *, int ); |
21 |
extern int IMAP_Literal_Read( ITD_Struct * ); |
22 |
extern void HandleRequest( int ); |
23 |
extern char *memtok( char *, char *, char ** ); |
24 |
diff -ru up-imapproxy-1.2.2/src/imapcommon.c up-imapproxy-1.2.2-fixed/src/imapcommon.c |
25 |
--- src/imapcommon.c 2004-07-23 16:17:25.000000000 +0300 |
26 |
+++ src/imapcommon.c.orig 2004-11-07 18:54:05.000000000 +0200 |
27 |
@@ -428,7 +428,7 @@ |
28 |
|
29 |
/* Read & throw away the banner line from the server */ |
30 |
|
31 |
- if ( IMAP_Line_Read( &Server ) == -1 ) |
32 |
+ if ( IMAP_Line_Read( &Server, 0 ) == -1 ) |
33 |
{ |
34 |
syslog(LOG_INFO, "LOGIN: '%s' (%s:%d) failed: No banner line received from IMAP server", Username, ClientAddr, sin_port ); |
35 |
goto fail; |
36 |
@@ -451,7 +451,7 @@ |
37 |
/* |
38 |
* Read the server response |
39 |
*/ |
40 |
- if ( ( rc = IMAP_Line_Read( &Server ) ) == -1 ) |
41 |
+ if ( ( rc = IMAP_Line_Read( &Server, 0 ) ) == -1 ) |
42 |
{ |
43 |
syslog(LOG_INFO, "STARTTLS failed: No response from IMAP server after sending STARTTLS command" ); |
44 |
goto fail; |
45 |
@@ -555,7 +555,7 @@ |
46 |
/* |
47 |
* the server response should be a go ahead |
48 |
*/ |
49 |
- if ( ( rc = IMAP_Line_Read( &Server ) ) == -1 ) |
50 |
+ if ( ( rc = IMAP_Line_Read( &Server, 0 ) ) == -1 ) |
51 |
{ |
52 |
syslog(LOG_INFO, "LOGIN: '%s' (%s:%d) failed: Failed to receive go-ahead from IMAP server after sending LOGIN command", Username, ClientAddr, sin_port ); |
53 |
goto fail; |
54 |
@@ -611,7 +611,7 @@ |
55 |
*/ |
56 |
for ( ;; ) |
57 |
{ |
58 |
- if ( ( rc = IMAP_Line_Read( &Server ) ) == -1 ) |
59 |
+ if ( ( rc = IMAP_Line_Read( &Server, 0 ) ) == -1 ) |
60 |
{ |
61 |
syslog(LOG_INFO, "LOGIN: '%s' (%s:%d) failed: No response from IMAP server after sending LOGIN command", Username, ClientAddr, sin_port ); |
62 |
goto fail; |
63 |
@@ -951,7 +951,8 @@ |
64 |
extern int IMAP_Literal_Read( ITD_Struct *ITD ) |
65 |
{ |
66 |
char *fn = "IMAP_Literal_Read()"; |
67 |
- int Status, i, j; |
68 |
+ int Status; |
69 |
+ unsigned int i, j; |
70 |
struct pollfd fds[2]; |
71 |
nfds_t nfds; |
72 |
int pollstatus; |
73 |
@@ -1080,10 +1081,11 @@ |
74 |
* process. |
75 |
*-- |
76 |
*/ |
77 |
-extern int IMAP_Line_Read( ITD_Struct *ITD ) |
78 |
+extern int IMAP_Line_Read( ITD_Struct *ITD, int useLiterals ) |
79 |
{ |
80 |
char *CP; |
81 |
- int Status, i, j; |
82 |
+ int Status; |
83 |
+ unsigned int i, j; |
84 |
char *fn = "IMAP_Line_Read()"; |
85 |
char *EndOfBuffer; |
86 |
|
87 |
@@ -1152,7 +1154,8 @@ |
88 |
* string literal is coming next. How do we know? |
89 |
* If it is, the line will end with {bytecount}. |
90 |
*/ |
91 |
- if ( ((CP - ITD->ReadBuf + 1) > 2 ) && ( *(CP - 2) == '}' )) |
92 |
+ if ( ((CP - ITD->ReadBuf + 1) > 2 ) && ( *(CP - 2) == '}' ) |
93 |
+ && useLiterals) |
94 |
{ |
95 |
char *LiteralEnd; |
96 |
char *LiteralStart; |
97 |
diff -ru up-imapproxy-1.2.2/src/main.c up-imapproxy-1.2.2-fixed/src/main.c |
98 |
--- src/main.c 2004-07-23 16:17:25.000000000 +0300 |
99 |
+++ src/main.c.orig 2004-11-07 18:52:41.000000000 +0200 |
100 |
@@ -931,7 +931,7 @@ |
101 |
* The first thing we get back from the server should be the |
102 |
* banner string. |
103 |
*/ |
104 |
- BytesRead = IMAP_Line_Read( &itd ); |
105 |
+ BytesRead = IMAP_Line_Read( &itd, 0 ); |
106 |
if ( BytesRead == -1 ) |
107 |
{ |
108 |
syslog( LOG_ERR, "%s: Error reading banner line from server on initial connection: %s -- Exiting.", fn, strerror( errno ) ); |
109 |
@@ -973,7 +973,7 @@ |
110 |
* The second will be the OK response with the tag in it. |
111 |
*/ |
112 |
|
113 |
- BytesRead = IMAP_Line_Read( &itd ); |
114 |
+ BytesRead = IMAP_Line_Read( &itd, 0 ); |
115 |
if ( BytesRead == -1 ) |
116 |
{ |
117 |
syslog( LOG_ERR, "%s: Failed to read capability response from server: %s -- exiting.", fn, strerror( errno ) ); |
118 |
@@ -986,7 +986,7 @@ |
119 |
|
120 |
|
121 |
/* Now read the tagged response and make sure it's OK */ |
122 |
- BytesRead = IMAP_Line_Read( &itd ); |
123 |
+ BytesRead = IMAP_Line_Read( &itd, 0 ); |
124 |
if ( BytesRead == -1 ) |
125 |
{ |
126 |
syslog( LOG_ERR, "%s: Failed to read capability response from server: %s -- exiting.", fn, strerror( errno ) ); |
127 |
@@ -1011,7 +1011,7 @@ |
128 |
} |
129 |
|
130 |
/* read the final OK logout */ |
131 |
- BytesRead = IMAP_Line_Read( &itd ); |
132 |
+ BytesRead = IMAP_Line_Read( &itd, 0 ); |
133 |
if ( BytesRead == -1 ) |
134 |
{ |
135 |
syslog(LOG_WARNING, "%s: IMAP_Line_Read() failed on LOGOUT -- Ignoring", fn ); |
136 |
diff -ru up-imapproxy-1.2.2/src/request.c up-imapproxy-1.2.2-fixed/src/request.c |
137 |
--- src/request.c 2004-07-23 16:17:26.000000000 +0300 |
138 |
+++ src/request.c.orig 2004-11-07 19:05:09.000000000 +0200 |
139 |
@@ -433,6 +433,7 @@ |
140 |
} |
141 |
|
142 |
strncpy( TraceUser, Username, sizeof TraceUser - 1 ); |
143 |
+ TraceUser[sizeof TraceUser - 1] = '\0'; |
144 |
|
145 |
snprintf( SendBuf, BufLen, "%s OK Tracing enabled\r\n", Tag ); |
146 |
if ( IMAP_Write( itd->conn, SendBuf, strlen(SendBuf) ) == -1 ) |
147 |
@@ -611,7 +612,7 @@ |
148 |
* The response from the client should be a base64 encoded version of the |
149 |
* username. |
150 |
*/ |
151 |
- BytesRead = IMAP_Line_Read( Client ); |
152 |
+ BytesRead = IMAP_Line_Read( Client, 0 ); |
153 |
|
154 |
if ( BytesRead == -1 ) |
155 |
{ |
156 |
@@ -654,7 +655,7 @@ |
157 |
return( -1 ); |
158 |
} |
159 |
|
160 |
- BytesRead = IMAP_Line_Read( Client ); |
161 |
+ BytesRead = IMAP_Line_Read( Client, 0 ); |
162 |
|
163 |
if ( BytesRead == -1 ) |
164 |
{ |
165 |
@@ -1097,7 +1098,7 @@ |
166 |
{ |
167 |
do |
168 |
{ |
169 |
- status = IMAP_Line_Read( Client ); |
170 |
+ status = IMAP_Line_Read( Client, 1 ); |
171 |
|
172 |
if ( status == -1 ) |
173 |
{ |
174 |
@@ -1152,7 +1153,7 @@ |
175 |
if ( Server->LiteralBytesRemaining ) |
176 |
break; |
177 |
|
178 |
- status = IMAP_Line_Read( Server ); |
179 |
+ status = IMAP_Line_Read( Server, 1 ); |
180 |
|
181 |
/* |
182 |
* If there's an error reading from the server, |
183 |
@@ -1266,7 +1267,7 @@ |
184 |
if ( ! Client->NonSyncLiteral ) |
185 |
{ |
186 |
/* we have to wait for a go-ahead */ |
187 |
- status = IMAP_Line_Read( Server ); |
188 |
+ status = IMAP_Line_Read( Server, 0 ); |
189 |
if ( Server->TraceOn ) |
190 |
{ |
191 |
snprintf( TraceBuf, sizeof TraceBuf - 1, "\n\n-----> C= %d %s SERVER: sd [%d]\n", time( 0 ), ( (TraceUser) ? TraceUser : "Null username" ), Server->conn->sd ); |
192 |
@@ -1473,7 +1474,19 @@ |
193 |
|
194 |
PollFailCount = 0; |
195 |
|
196 |
- BytesRead = IMAP_Line_Read( &Client ); |
197 |
+ while ( Client.LiteralBytesRemaining ) |
198 |
+ { |
199 |
+ BytesRead = IMAP_Literal_Read( &Client ); |
200 |
+ |
201 |
+ if ( BytesRead == -1 ) |
202 |
+ { |
203 |
+ IMAPCount->CurrentClientConnections--; |
204 |
+ close( Client.conn->sd ); |
205 |
+ return; |
206 |
+ } |
207 |
+ } |
208 |
+ |
209 |
+ BytesRead = IMAP_Line_Read( &Client, 1 ); |
210 |
|
211 |
if ( BytesRead == -1 ) |
212 |
{ |
213 |
@@ -1530,6 +1543,7 @@ |
214 |
* appropriate... |
215 |
*/ |
216 |
strncpy( S_Tag, Tag, MAXTAGLEN - 1 ); |
217 |
+ S_Tag[MAXTAGLEN - 1] = '\0'; |
218 |
if ( ! strcasecmp( (const char *)Command, "NOOP" ) ) |
219 |
{ |
220 |
cmd_noop( &Client, S_Tag ); |
221 |
@@ -1569,6 +1583,7 @@ |
222 |
if ( Tag ) |
223 |
{ |
224 |
strncpy( S_Tag, Tag, MAXTAGLEN - 1 ); |
225 |
+ S_Tag[MAXTAGLEN - 1] = '\0'; |
226 |
cmd_logout( &Client, S_Tag ); |
227 |
} |
228 |
} |
229 |
@@ -1641,7 +1656,8 @@ |
230 |
} |
231 |
continue; |
232 |
} |
233 |
- strncpy( S_UserName, Username, sizeof S_UserName - 1 ); |
234 |
+ strncpy( S_UserName, Username, sizeof S_UserName - 1 ); |
235 |
+ S_UserName[sizeof S_UserName - 1] = '\0'; |
236 |
|
237 |
/* |
238 |
* Clients can send the password as a literal bytestream. Check |
239 |
@@ -1720,7 +1736,7 @@ |
240 |
* IMAP_Literal_Read() right now since it works properly |
241 |
* otherwise. |
242 |
*/ |
243 |
- rc = IMAP_Line_Read( &Client ); |
244 |
+ rc = IMAP_Line_Read( &Client, 1 ); |
245 |
} |
246 |
else |
247 |
{ |
248 |
@@ -1748,6 +1764,7 @@ |
249 |
|
250 |
*CP = '\0'; |
251 |
strncpy( S_Password, Lasts, sizeof S_Password - 1 ); |
252 |
+ S_Password[sizeof S_Password - 1] = '\0'; |
253 |
} |
254 |
|
255 |
|
256 |
@@ -1779,6 +1796,7 @@ |
257 |
if ( Tag ) |
258 |
{ |
259 |
strncpy( S_Tag, Tag, MAXTAGLEN - 1 ); |
260 |
+ S_Tag[MAXTAGLEN - 1] = '\0'; |
261 |
cmd_logout( &Client, S_Tag ); |
262 |
} |
263 |
} |
264 |
diff -ru up-imapproxy-1.2.2/src/select.c up-imapproxy-1.2.2-fixed/src/select.c |
265 |
--- src/select.c 2004-07-23 16:17:25.000000000 +0300 |
266 |
+++ src/select.c.orig 2004-11-07 18:56:01.000000000 +0200 |
267 |
@@ -356,7 +356,7 @@ |
268 |
return( -1 ); |
269 |
} |
270 |
|
271 |
- rc = IMAP_Line_Read( Server ); |
272 |
+ rc = IMAP_Line_Read( Server, 0 ); |
273 |
|
274 |
if ( ( rc == -1 ) || ( rc == 0 ) ) |
275 |
{ |
276 |
@@ -417,6 +417,7 @@ |
277 |
ISC->ISCTime = time( 0 ); |
278 |
|
279 |
strncpy( (char *)ISC->MailboxName, (const char *)MailboxName, MAXMAILBOXNAME - 1 ); |
280 |
+ ISC->MailboxName[MAXMAILBOXNAME - 1] = '\0'; |
281 |
|
282 |
return( 0 ); |