tests/gnrc_sock_ip: add test case to test NULL pointer dereference

This commit is contained in:
Martine S. Lenders 2020-09-07 09:15:27 +02:00
parent b2da5d0687
commit 779143cd94
No known key found for this signature in database
GPG Key ID: CCD317364F63286F
2 changed files with 15 additions and 3 deletions

View File

@ -366,7 +366,7 @@ static void test_sock_ip_recv_buf__success(void)
assert(_check_net()); 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 }, static const sock_ip_ep_t remote = { .addr = { .ipv6 = _TEST_ADDR_REMOTE },
.family = AF_INET }; .family = AF_INET };
@ -376,6 +376,16 @@ static void test_sock_ip_send__EAFNOSUPPORT(void)
expect(_check_net()); 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 void test_sock_ip_send__EINVAL_addr(void)
{ {
static const sock_ip_ep_t local = { .addr = { .ipv6 = _TEST_ADDR_LOCAL }, static const sock_ip_ep_t local = { .addr = { .ipv6 = _TEST_ADDR_LOCAL },
@ -641,7 +651,8 @@ int main(void)
CALL(test_sock_ip_recv__non_blocking()); CALL(test_sock_ip_recv__non_blocking());
CALL(test_sock_ip_recv_buf__success()); CALL(test_sock_ip_recv_buf__success());
_prepare_send_checks(); _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_addr());
CALL(test_sock_ip_send__EINVAL_netif()); CALL(test_sock_ip_send__EINVAL_netif());
CALL(test_sock_ip_send__ENOTCONN()); CALL(test_sock_ip_send__ENOTCONN());

View File

@ -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()")
child.expect_exact(u"Calling test_sock_ip_recv__unsocketed_with_remote()") 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_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_addr()")
child.expect_exact(u"Calling test_sock_ip_send__EINVAL_netif()") child.expect_exact(u"Calling test_sock_ip_send__EINVAL_netif()")
child.expect_exact(u"Calling test_sock_ip_send__ENOTCONN()") child.expect_exact(u"Calling test_sock_ip_send__ENOTCONN()")