Commit d1e06eeb d1e06eeb9401fea5c5e634888377c48ed682e13c by Sergey Poznyakoff

Bugfixes

* libmailutils/filter/base64.c (_base64_encoder): Fix for the case
when cmd==mu_filter_lastbuf and isize==0.

* libmailutils/stream/tcp.c (mu_tcp_stream_create_with_source_ip)
(mu_tcp_stream_create_with_source_host): Don't treat EAGAIN and
EINPROGRESS as errors.
* libproto/mailer/smtp.c (smtp_open): Free sockaddr if
mu_tcp_stream_create_from_sa failed.
* libproto/pop/mbox.c (pop_open): Likewise.
* mu/imap.c (com_connect): Likewise.
* mu/pop.c (com_connect): Likewise.
1 parent dd07fe07
...@@ -286,30 +286,40 @@ _base64_encoder (void *xd, ...@@ -286,30 +286,40 @@ _base64_encoder (void *xd,
286 286
287 if (!(consumed + 3 <= isize || pad)) 287 if (!(consumed + 3 <= isize || pad))
288 break; 288 break;
289 289
290 *optr++ = b64tab[ptr[0] >> 2]; 290 if (consumed == isize)
291 nbytes++;
292 lp->cur_len++;
293 consumed++;
294 switch (isize - consumed)
295 { 291 {
296 default:
297 consumed++;
298 y = b64tab[ptr[2] & 0x3f];
299 c2 = ptr[2] >> 6;
300 case 1:
301 consumed++;
302 x = b64tab[((ptr[1] << 2) + c2) & 0x3f];
303 c1 = (ptr[1] >> 4);
304 case 0:
305 lp->save[0] = b64tab[((ptr[0] << 4) + c1) & 0x3f];
306 lp->save[1] = x; 292 lp->save[1] = x;
307 lp->save[2] = y; 293 lp->save[2] = y;
308 lp->idx = 0; 294 lp->idx = 1;
309 lp->state = base64_rollback; 295 lp->state = base64_rollback;
310 } 296 }
311 297 else
312 ptr += 3; 298 {
299 *optr++ = b64tab[ptr[0] >> 2];
300 nbytes++;
301 lp->cur_len++;
302 consumed++;
303 switch (isize - consumed)
304 {
305 default:
306 consumed++;
307 y = b64tab[ptr[2] & 0x3f];
308 c2 = ptr[2] >> 6;
309 case 1:
310 consumed++;
311 x = b64tab[((ptr[1] << 2) + c2) & 0x3f];
312 c1 = (ptr[1] >> 4);
313 case 0:
314 lp->save[0] = b64tab[((ptr[0] << 4) + c1) & 0x3f];
315 lp->save[1] = x;
316 lp->save[2] = y;
317 lp->idx = 0;
318 lp->state = base64_rollback;
319 }
320
321 ptr += 3;
322 }
313 pad = 0; 323 pad = 0;
314 } 324 }
315 325
......
...@@ -332,7 +332,7 @@ mu_tcp_stream_create_with_source_ip (mu_stream_t *pstream, ...@@ -332,7 +332,7 @@ mu_tcp_stream_create_with_source_ip (mu_stream_t *pstream,
332 } 332 }
333 333
334 rc = mu_tcp_stream_create_from_sa (pstream, remote_addr, source_addr, flags); 334 rc = mu_tcp_stream_create_from_sa (pstream, remote_addr, source_addr, flags);
335 if (rc) 335 if (rc && !(rc == EAGAIN || rc == EINPROGRESS))
336 { 336 {
337 mu_sockaddr_free (remote_addr); 337 mu_sockaddr_free (remote_addr);
338 mu_sockaddr_free (source_addr); 338 mu_sockaddr_free (source_addr);
...@@ -371,7 +371,7 @@ mu_tcp_stream_create_with_source_host (mu_stream_t *stream, ...@@ -371,7 +371,7 @@ mu_tcp_stream_create_with_source_host (mu_stream_t *stream,
371 } 371 }
372 372
373 rc = mu_tcp_stream_create_from_sa (stream, remote_addr, source_addr, flags); 373 rc = mu_tcp_stream_create_from_sa (stream, remote_addr, source_addr, flags);
374 if (rc) 374 if (rc && !(rc == EAGAIN || rc == EINPROGRESS))
375 { 375 {
376 mu_sockaddr_free (remote_addr); 376 mu_sockaddr_free (remote_addr);
377 mu_sockaddr_free (source_addr); 377 mu_sockaddr_free (source_addr);
......
...@@ -175,7 +175,10 @@ smtp_open (mu_mailer_t mailer, int flags) ...@@ -175,7 +175,10 @@ smtp_open (mu_mailer_t mailer, int flags)
175 rc = mu_tcp_stream_create_from_sa (&mailer->stream, sa, NULL, 175 rc = mu_tcp_stream_create_from_sa (&mailer->stream, sa, NULL,
176 mailer->flags); 176 mailer->flags);
177 if (rc) 177 if (rc)
178 return rc; 178 {
179 mu_sockaddr_free (sa);
180 return rc;
181 }
179 mu_stream_set_buffer (mailer->stream, mu_buffer_line, 0); 182 mu_stream_set_buffer (mailer->stream, mu_buffer_line, 0);
180 } 183 }
181 mu_smtp_set_carrier (smtp_mailer->smtp, mailer->stream); 184 mu_smtp_set_carrier (smtp_mailer->smtp, mailer->stream);
......
...@@ -132,7 +132,10 @@ pop_open (mu_mailbox_t mbox, int flags) ...@@ -132,7 +132,10 @@ pop_open (mu_mailbox_t mbox, int flags)
132 132
133 status = mu_tcp_stream_create_from_sa (&stream, sa, NULL, mbox->flags); 133 status = mu_tcp_stream_create_from_sa (&stream, sa, NULL, mbox->flags);
134 if (status) 134 if (status)
135 return status; 135 {
136 mu_sockaddr_free (sa);
137 return status;
138 }
136 #ifdef WITH_TLS 139 #ifdef WITH_TLS
137 if (mpd->pops) 140 if (mpd->pops)
138 { 141 {
......
...@@ -217,7 +217,11 @@ com_connect (int argc, char **argv) ...@@ -217,7 +217,11 @@ com_connect (int argc, char **argv)
217 hints.socktype = SOCK_STREAM; 217 hints.socktype = SOCK_STREAM;
218 status = mu_sockaddr_from_node (&sa, argv[0], argv[1], &hints); 218 status = mu_sockaddr_from_node (&sa, argv[0], argv[1], &hints);
219 if (status == 0) 219 if (status == 0)
220 status = mu_tcp_stream_create_from_sa (&tcp, sa, NULL, 0); 220 {
221 status = mu_tcp_stream_create_from_sa (&tcp, sa, NULL, 0);
222 if (status)
223 mu_sockaddr_free (sa);
224 }
221 if (status == 0) 225 if (status == 0)
222 { 226 {
223 #ifdef WITH_TLS 227 #ifdef WITH_TLS
......
...@@ -542,6 +542,8 @@ com_connect (int argc, char **argv) ...@@ -542,6 +542,8 @@ com_connect (int argc, char **argv)
542 { 542 {
543 n = port_from_sa (sa); 543 n = port_from_sa (sa);
544 status = mu_tcp_stream_create_from_sa (&tcp, sa, NULL, 0); 544 status = mu_tcp_stream_create_from_sa (&tcp, sa, NULL, 0);
545 if (status)
546 mu_sockaddr_free (sa);
545 } 547 }
546 if (status == 0) 548 if (status == 0)
547 { 549 {
......