mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
clif: Don't access any data if input is empty
This is relevant as clif_decode_link may invoke clif_get_attr with input_len == 0.
This commit is contained in:
parent
609c9ada34
commit
0d141bf93a
@ -258,6 +258,10 @@ ssize_t clif_get_attr(const char *input, size_t input_len, clif_attr_t *attr)
|
||||
attr->value = NULL;
|
||||
attr->key = NULL;
|
||||
|
||||
if (input_len == 0) {
|
||||
return CLIF_NOT_FOUND;
|
||||
}
|
||||
|
||||
/* an attribute should start with the separator */
|
||||
if (*pos != LF_ATTR_SEPARATOR_C) {
|
||||
DEBUG("Attribute should start with separator, found %c\n", *pos);
|
||||
|
@ -285,12 +285,23 @@ static void test_clif_get_attr_missing_value(void)
|
||||
TEST_ASSERT_EQUAL_INT(strlen(input), r);
|
||||
}
|
||||
|
||||
static void test_clif_get_attr_empty(void)
|
||||
{
|
||||
clif_attr_t attr;
|
||||
|
||||
/* clif_get_attr used to access data even if input was empty.
|
||||
* See: https://github.com/RIOT-OS/RIOT/pull/15947 */
|
||||
int r = clif_get_attr(NULL, 0, &attr);
|
||||
TEST_ASSERT_EQUAL_INT(CLIF_NOT_FOUND, r);
|
||||
}
|
||||
|
||||
Test *tests_clif_tests(void)
|
||||
{
|
||||
EMB_UNIT_TESTFIXTURES(fixtures) {
|
||||
new_TestFixture(test_clif_encode_links),
|
||||
new_TestFixture(test_clif_decode_links),
|
||||
new_TestFixture(test_clif_get_attr_missing_value),
|
||||
new_TestFixture(test_clif_get_attr_empty)
|
||||
};
|
||||
|
||||
EMB_UNIT_TESTCALLER(clif_tests, NULL, NULL, fixtures);
|
||||
|
Loading…
Reference in New Issue
Block a user