Merge pull request #15947 from nmeum/pr/clif_get_attr_empty
clif: Don't access any data if input is empty
This commit is contained in:
commit
85da504d2d
@ -258,6 +258,10 @@ ssize_t clif_get_attr(const char *input, size_t input_len, clif_attr_t *attr)
|
|||||||
attr->value = NULL;
|
attr->value = NULL;
|
||||||
attr->key = NULL;
|
attr->key = NULL;
|
||||||
|
|
||||||
|
if (input_len == 0) {
|
||||||
|
return CLIF_NOT_FOUND;
|
||||||
|
}
|
||||||
|
|
||||||
/* an attribute should start with the separator */
|
/* an attribute should start with the separator */
|
||||||
if (*pos != LF_ATTR_SEPARATOR_C) {
|
if (*pos != LF_ATTR_SEPARATOR_C) {
|
||||||
DEBUG("Attribute should start with separator, found %c\n", *pos);
|
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);
|
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)
|
Test *tests_clif_tests(void)
|
||||||
{
|
{
|
||||||
EMB_UNIT_TESTFIXTURES(fixtures) {
|
EMB_UNIT_TESTFIXTURES(fixtures) {
|
||||||
new_TestFixture(test_clif_encode_links),
|
new_TestFixture(test_clif_encode_links),
|
||||||
new_TestFixture(test_clif_decode_links),
|
new_TestFixture(test_clif_decode_links),
|
||||||
new_TestFixture(test_clif_get_attr_missing_value),
|
new_TestFixture(test_clif_get_attr_missing_value),
|
||||||
|
new_TestFixture(test_clif_get_attr_empty)
|
||||||
};
|
};
|
||||||
|
|
||||||
EMB_UNIT_TESTCALLER(clif_tests, NULL, NULL, fixtures);
|
EMB_UNIT_TESTCALLER(clif_tests, NULL, NULL, fixtures);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user