Skip to content

Commit

Permalink
Bug fix - getpeername() is called for no reason and may fail with ENO…
Browse files Browse the repository at this point in the history
…TCONN
  • Loading branch information
dimkr committed Sep 9, 2018
1 parent 9290f2c commit aa96595
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
18 changes: 6 additions & 12 deletions src/b6b_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ static struct b6b_obj *b6b_socket_new(struct b6b_interp *interp,

s->fd = fd;
memcpy(&s->addr, addr, (size_t)alen);

if (peer)
memcpy(&s->peer, peer, (size_t)plen);
else
Expand Down Expand Up @@ -559,10 +560,10 @@ static int b6b_socket_stream_accept(struct b6b_interp *interp,
const struct b6b_strm_ops *ops,
const char *type)
{
struct sockaddr_storage addr, peer;
socklen_t alen = sizeof(addr), plen = sizeof(peer);
struct sockaddr_storage peer;
socklen_t plen = sizeof(peer);
const struct b6b_socket *s = (const struct b6b_socket *)priv;
int fd, err;
int fd;

fd = accept4(s->fd,
(struct sockaddr *)&peer,
Expand All @@ -578,17 +579,10 @@ static int b6b_socket_stream_accept(struct b6b_interp *interp,
return 0;
}

if (getpeername(fd, (struct sockaddr *)&addr, &alen) < 0) {
err = errno;
close(fd);
b6b_return_strerror(interp, err);
return 0;
}

*o = b6b_socket_new(interp,
fd,
(const struct sockaddr *)&addr,
alen,
NULL,
0,
(const struct sockaddr *)&peer,
plen,
type,
Expand Down
2 changes: 1 addition & 1 deletion src/b6b_strm.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ static enum b6b_res b6b_strm_writeln(struct b6b_interp *interp,
}

static enum b6b_res b6b_strm_accept(struct b6b_interp *interp,
struct b6b_strm *strm)
struct b6b_strm *strm)
{
struct b6b_obj *l, *o;

Expand Down

0 comments on commit aa96595

Please sign in to comment.