Skip to content

Commit

Permalink
make client socket non blocking to avoid evil client from causing
Browse files Browse the repository at this point in the history
trouble in a SSL handshake. while at it, make event masking a bit
more strict to avoid possible bugs
  • Loading branch information
poolpOrg committed May 16, 2013
1 parent 4797d6e commit d94be90
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
8 changes: 5 additions & 3 deletions smtpd/ioev.c
Expand Up @@ -676,11 +676,11 @@ io_start_tls(struct io *io, void *ssl)
if (mode == IO_WRITE) {
io->state = IO_STATE_CONNECT_SSL;
SSL_set_connect_state(io->ssl);
io_reset(io, EV_READ | EV_WRITE, io_dispatch_connect_ssl);
io_reset(io, EV_WRITE, io_dispatch_connect_ssl);
} else {
io->state = IO_STATE_ACCEPT_SSL;
SSL_set_accept_state(io->ssl);
io_reset(io, EV_READ | EV_WRITE, io_dispatch_accept_ssl);
io_reset(io, EV_READ, io_dispatch_accept_ssl);
}

return (0);
Expand Down Expand Up @@ -854,14 +854,16 @@ io_dispatch_write_ssl(int fd, short event, void *humppa)
void
io_reload_ssl(struct io *io)
{
short ev = EV_READ|EV_WRITE;
short ev = 0;
void (*dispatch)(int, short, void*) = NULL;

switch (io->state) {
case IO_STATE_CONNECT_SSL:
ev = EV_WRITE;
dispatch = io_dispatch_connect_ssl;
break;
case IO_STATE_ACCEPT_SSL:
ev = EV_READ;
dispatch = io_dispatch_accept_ssl;
break;
case IO_STATE_UP:
Expand Down
1 change: 1 addition & 0 deletions smtpd/smtp.c
Expand Up @@ -428,6 +428,7 @@ smtp_accept(int fd, short event, void *p)
close(sock);
return;
}
io_set_blocking(sock, 0);

sessions++;
stat_increment("smtp.session", 1);
Expand Down

0 comments on commit d94be90

Please sign in to comment.