Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RIOT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cm-projects
RIOT
Commits
dd53bb89
Commit
dd53bb89
authored
6 years ago
by
Kaspar Schleiser
Browse files
Options
Downloads
Patches
Plain Diff
tests/unittests/nanocoap: add test case for option_count overflow
parent
afe3d676
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/unittests/tests-nanocoap/tests-nanocoap.c
+49
-0
49 additions, 0 deletions
tests/unittests/tests-nanocoap/tests-nanocoap.c
with
49 additions
and
0 deletions
tests/unittests/tests-nanocoap/tests-nanocoap.c
+
49
−
0
View file @
dd53bb89
...
...
@@ -15,6 +15,7 @@
#include
<stdint.h>
#include
<stdbool.h>
#include
<string.h>
#include
<stdio.h>
#include
"embUnit.h"
...
...
@@ -433,6 +434,53 @@ static void test_nanocoap__server_reply_simple_con(void)
TEST_ASSERT_EQUAL_INT
(
COAP_TYPE_ACK
,
coap_get_type
(
&
pkt
));
}
static
void
test_nanocoap__server_option_count_overflow_check
(
void
)
{
/* this test passes a forged CoAP packet containing 42 options (provided by
* @nmeum in #10753) to coap_parse(). The used coap_pkt_t is part of a
* struct, followed by an array of 42 coap_option_t. The array is cleared
* before the call to coap_parse(). If the overflow protection is working,
* the array must still be clear after parsing the packet, and the proper
* error code (-ENOMEM) is returned. Otherwise, the parsing wrote past
* scratch.pkt, thus the array is not zeroed anymore.
*/
static
uint8_t
pkt_data
[]
=
{
0x40
,
0x01
,
0x09
,
0x26
,
0x01
,
0x17
,
0x11
,
0x17
,
0x11
,
0x17
,
0x11
,
0x17
,
0x11
,
0x17
,
0x11
,
0x17
,
0x11
,
0x17
,
0x11
,
0x17
,
0x11
,
0x17
,
0x11
,
0x17
,
0x11
,
0x17
,
0x11
,
0x17
,
0x11
,
0x17
,
0x11
,
0x17
,
0x11
,
0x17
,
0x11
,
0x17
,
0x11
,
0x17
,
0x11
,
0x17
,
0x11
,
0x17
,
0x11
,
0x17
,
0x11
,
0x17
,
0x11
,
0x17
,
0x11
,
0x17
,
0x11
,
0x17
,
0x11
,
0x17
,
0x11
,
0x17
,
0x11
,
0x17
,
0x11
,
0x17
,
0x11
,
0x17
,
0x11
,
0x17
,
0x11
,
0x17
,
0x11
,
0x17
,
0x11
,
0x17
,
0x11
,
0x17
,
0x11
,
0x17
,
0x11
,
0x17
,
0x11
,
0x17
,
0x11
,
0x17
,
0x11
,
0x17
,
0x11
,
0x17
,
0x11
,
0x17
,
0x11
,
0x17
};
/* ensure NANOCOAP_NOPTS_MAX is actually lower than 42 */
TEST_ASSERT
(
NANOCOAP_NOPTS_MAX
<
42
);
struct
{
coap_pkt_t
pkt
;
uint8_t
guard_data
[
42
*
sizeof
(
coap_optpos_t
)];
}
scratch
;
memset
(
&
scratch
,
0
,
sizeof
(
scratch
));
int
res
=
coap_parse
(
&
scratch
.
pkt
,
pkt_data
,
sizeof
(
pkt_data
));
/* check if any byte of the guard_data array is non-zero */
int
dirty
=
0
;
volatile
uint8_t
*
pos
=
scratch
.
guard_data
;
for
(
size_t
i
=
0
;
i
<
sizeof
(
scratch
.
guard_data
);
i
++
)
{
if
(
*
pos
)
{
dirty
=
1
;
break
;
}
}
TEST_ASSERT_EQUAL_INT
(
0
,
dirty
);
TEST_ASSERT_EQUAL_INT
(
-
ENOMEM
,
res
);
}
Test
*
tests_nanocoap_tests
(
void
)
{
EMB_UNIT_TESTFIXTURES
(
fixtures
)
{
...
...
@@ -450,6 +498,7 @@ Test *tests_nanocoap_tests(void)
new_TestFixture
(
test_nanocoap__server_reply_simple
),
new_TestFixture
(
test_nanocoap__server_get_req_con
),
new_TestFixture
(
test_nanocoap__server_reply_simple_con
),
new_TestFixture
(
test_nanocoap__server_option_count_overflow_check
),
};
EMB_UNIT_TESTCALLER
(
nanocoap_tests
,
NULL
,
NULL
,
fixtures
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment