Skip to content

Commit

Permalink
Land rapid7#205, check for a valid channel context
Browse files Browse the repository at this point in the history
  • Loading branch information
busterb committed Dec 22, 2020
2 parents a09f308 + 55fc376 commit 5955f9d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
18 changes: 17 additions & 1 deletion mettle/src/stdapi/net/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,21 @@ static ssize_t
tcp_client_read(struct channel *c, void *buf, size_t len)
{
struct tcp_client_channel *tcc = channel_get_ctx(c);
if (tcc == NULL) {
errno = EIO;
return -1;
}
return network_client_read(tcc->nc, buf, len);
}

static ssize_t
tcp_client_write(struct channel *c, void *buf, size_t len)
{
struct tcp_client_channel *tcc = channel_get_ctx(c);
if (tcc == NULL) {
errno = EIO;
return -1;
}
return network_client_write(tcc->nc, buf, len);
}

Expand Down Expand Up @@ -332,8 +340,12 @@ udp_client_new(struct tlv_handler_ctx *ctx, struct channel *c)
static ssize_t
udp_client_read(struct channel *c, void *buf, size_t len)
{
struct udp_client_channel *ucc = channel_get_ctx(c);
size_t msg_len;
struct udp_client_channel *ucc = channel_get_ctx(c);
if (ucc == NULL) {
errno = EIO;
return -1;
}
void *msg_buf = network_client_read_msg(ucc->nc, &msg_len);
memcpy(buf, msg_buf, TYPESAFE_MIN(len, msg_len));
return msg_len;
Expand All @@ -343,6 +355,10 @@ static ssize_t
udp_client_write(struct channel *c, void *buf, size_t len)
{
struct udp_client_channel *ucc = channel_get_ctx(c);
if (ucc == NULL) {
errno = EIO;
return -1;
}
return network_client_write(ucc->nc, buf,
TYPESAFE_MIN(len, IP_LEN_MAX - IP_HDR_LEN - UDP_HDR_LEN));
}
Expand Down
8 changes: 8 additions & 0 deletions mettle/src/stdapi/net/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,20 @@ static int tcp_server_free(struct channel *c)
static ssize_t tcp_conn_read(struct channel *c, void *buf, size_t len)
{
struct tcp_server_conn *conn = channel_get_ctx(c);
if (conn == NULL) {
errno = EIO;
return -1;
}
return bufferev_read(conn->be, buf, len);
}

static ssize_t tcp_conn_write(struct channel *c, void *buf, size_t len)
{
struct tcp_server_conn *conn = channel_get_ctx(c);
if (conn == NULL) {
errno = EIO;
return -1;
}
return bufferev_write(conn->be, buf, len);
}

Expand Down

0 comments on commit 5955f9d

Please sign in to comment.