Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gnrc_sock_ip: fix NULL pointer dereference #14963

Merged
merged 2 commits into from
Sep 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sys/net/gnrc/sock/ip/gnrc_sock_ip.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ ssize_t sock_ip_send(sock_ip_t *sock, const void *data, size_t len,
gnrc_ep_set(&rem, remote, sizeof(rem));
}
if ((remote != NULL) && (remote->family == AF_UNSPEC) &&
(sock->remote.family != AF_UNSPEC)) {
(sock != NULL) && (sock->remote.family != AF_UNSPEC)) {
/* remote was set on create so take its family */
rem.family = sock->remote.family;
}
Expand Down
15 changes: 13 additions & 2 deletions tests/gnrc_sock_ip/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ static void test_sock_ip_recv_buf__success(void)
assert(_check_net());
}

static void test_sock_ip_send__EAFNOSUPPORT(void)
static void test_sock_ip_send__EAFNOSUPPORT_INET(void)
{
static const sock_ip_ep_t remote = { .addr = { .ipv6 = _TEST_ADDR_REMOTE },
.family = AF_INET };
Expand All @@ -376,6 +376,16 @@ static void test_sock_ip_send__EAFNOSUPPORT(void)
expect(_check_net());
}

static void test_sock_ip_send__EAFNOSUPPORT_UNSPEC(void)
{
static const sock_ip_ep_t remote = { .addr = { .ipv6 = _TEST_ADDR_REMOTE },
.family = AF_UNSPEC };

expect(-EAFNOSUPPORT == sock_ip_send(NULL, "ABCD", sizeof("ABCD"),
_TEST_PROTO, &remote));
expect(_check_net());
}

static void test_sock_ip_send__EINVAL_addr(void)
{
static const sock_ip_ep_t local = { .addr = { .ipv6 = _TEST_ADDR_LOCAL },
Expand Down Expand Up @@ -641,7 +651,8 @@ int main(void)
CALL(test_sock_ip_recv__non_blocking());
CALL(test_sock_ip_recv_buf__success());
_prepare_send_checks();
CALL(test_sock_ip_send__EAFNOSUPPORT());
CALL(test_sock_ip_send__EAFNOSUPPORT_INET());
CALL(test_sock_ip_send__EAFNOSUPPORT_UNSPEC());
CALL(test_sock_ip_send__EINVAL_addr());
CALL(test_sock_ip_send__EINVAL_netif());
CALL(test_sock_ip_send__ENOTCONN());
Expand Down
3 changes: 2 additions & 1 deletion tests/gnrc_sock_ip/tests/01-run.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ def testfunc(child):
child.expect_exact(u"Calling test_sock_ip_recv__unsocketed()")
child.expect_exact(u"Calling test_sock_ip_recv__unsocketed_with_remote()")
child.expect_exact(u"Calling test_sock_ip_recv__with_timeout()")
child.expect_exact(u"Calling test_sock_ip_send__EAFNOSUPPORT()")
child.expect_exact(u"Calling test_sock_ip_send__EAFNOSUPPORT_INET()")
child.expect_exact(u"Calling test_sock_ip_send__EAFNOSUPPORT_UNSPEC()")
child.expect_exact(u"Calling test_sock_ip_send__EINVAL_addr()")
child.expect_exact(u"Calling test_sock_ip_send__EINVAL_netif()")
child.expect_exact(u"Calling test_sock_ip_send__ENOTCONN()")
Expand Down