Skip to content

Commit d94be90

Browse files
committed
make client socket non blocking to avoid evil client from causing
trouble in a SSL handshake. while at it, make event masking a bit more strict to avoid possible bugs
1 parent 4797d6e commit d94be90

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

smtpd/ioev.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -676,11 +676,11 @@ io_start_tls(struct io *io, void *ssl)
676676
if (mode == IO_WRITE) {
677677
io->state = IO_STATE_CONNECT_SSL;
678678
SSL_set_connect_state(io->ssl);
679-
io_reset(io, EV_READ | EV_WRITE, io_dispatch_connect_ssl);
679+
io_reset(io, EV_WRITE, io_dispatch_connect_ssl);
680680
} else {
681681
io->state = IO_STATE_ACCEPT_SSL;
682682
SSL_set_accept_state(io->ssl);
683-
io_reset(io, EV_READ | EV_WRITE, io_dispatch_accept_ssl);
683+
io_reset(io, EV_READ, io_dispatch_accept_ssl);
684684
}
685685

686686
return (0);
@@ -854,14 +854,16 @@ io_dispatch_write_ssl(int fd, short event, void *humppa)
854854
void
855855
io_reload_ssl(struct io *io)
856856
{
857-
short ev = EV_READ|EV_WRITE;
857+
short ev = 0;
858858
void (*dispatch)(int, short, void*) = NULL;
859859

860860
switch (io->state) {
861861
case IO_STATE_CONNECT_SSL:
862+
ev = EV_WRITE;
862863
dispatch = io_dispatch_connect_ssl;
863864
break;
864865
case IO_STATE_ACCEPT_SSL:
866+
ev = EV_READ;
865867
dispatch = io_dispatch_accept_ssl;
866868
break;
867869
case IO_STATE_UP:

smtpd/smtp.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ smtp_accept(int fd, short event, void *p)
428428
close(sock);
429429
return;
430430
}
431+
io_set_blocking(sock, 0);
431432

432433
sessions++;
433434
stat_increment("smtp.session", 1);

0 commit comments

Comments
 (0)