Skip to content

Commit e172f72

Browse files
rlubosfabiobaltieri
authored andcommitted
tests: net: lwm2m: content_json: Check for overflows
Add checks for int64_t overflows when parsing. Signed-off-by: Robert Lubos <[email protected]>
1 parent d7e2c1b commit e172f72

File tree

1 file changed

+11
-0
lines changed
  • tests/net/lib/lwm2m/content_json/src

1 file changed

+11
-0
lines changed

tests/net/lib/lwm2m/content_json/src/main.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,10 @@ ZTEST(net_content_json, test_get_s64)
525525
TEST_PAYLOAD(TEST_RES_S64, "v", "9223372036854775807"),
526526
TEST_PAYLOAD(TEST_RES_S64, "v", "-9223372036854775808"),
527527
};
528+
char * const payload_overflow[] = {
529+
TEST_PAYLOAD(TEST_RES_S64, "v", "9223372036854775808"),
530+
TEST_PAYLOAD(TEST_RES_S64, "v", "-9223372036854775809"),
531+
};
528532
int64_t expected_value[] = { 0, INT64_MAX, INT64_MIN };
529533

530534
test_msg.path.res_id = TEST_RES_S64;
@@ -536,6 +540,13 @@ ZTEST(net_content_json, test_get_s64)
536540
zassert_true(ret >= 0, "Error reported");
537541
zassert_equal(test_s64, expected_value[i], "Invalid value parsed");
538542
}
543+
544+
for (i = 0; i < ARRAY_SIZE(payload_overflow); i++) {
545+
test_payload_set(payload_overflow[i]);
546+
547+
ret = do_write_op_json(&test_msg);
548+
zassert_equal(ret, -EINVAL, "Error expected on too large value");
549+
}
539550
}
540551

541552
ZTEST(net_content_json_nodata, test_get_s64_nodata)

0 commit comments

Comments
 (0)