Commit e172f72e authored by Robert Lubos's avatar Robert Lubos Committed by Fabio Baltieri
Browse files

tests: net: lwm2m: content_json: Check for overflows



Add checks for int64_t overflows when parsing.

Signed-off-by: default avatarRobert Lubos <robert.lubos@nordicsemi.no>
parent d7e2c1b8
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -525,6 +525,10 @@ ZTEST(net_content_json, test_get_s64)
		TEST_PAYLOAD(TEST_RES_S64, "v", "9223372036854775807"),
		TEST_PAYLOAD(TEST_RES_S64, "v", "-9223372036854775808"),
	};
	char * const payload_overflow[] = {
		TEST_PAYLOAD(TEST_RES_S64, "v", "9223372036854775808"),
		TEST_PAYLOAD(TEST_RES_S64, "v", "-9223372036854775809"),
	};
	int64_t expected_value[] = { 0, INT64_MAX, INT64_MIN };

	test_msg.path.res_id = TEST_RES_S64;
@@ -536,6 +540,13 @@ ZTEST(net_content_json, test_get_s64)
		zassert_true(ret >= 0, "Error reported");
		zassert_equal(test_s64, expected_value[i], "Invalid value parsed");
	}

	for (i = 0; i < ARRAY_SIZE(payload_overflow); i++) {
		test_payload_set(payload_overflow[i]);

		ret = do_write_op_json(&test_msg);
		zassert_equal(ret, -EINVAL, "Error expected on too large value");
	}
}

ZTEST(net_content_json_nodata, test_get_s64_nodata)