Debian Codegraph @

tests/isc/parse_test.c

raw
1 /*
2 * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
3 *
4 * SPDX-License-Identifier: MPL-2.0
5 *
6 * This Source Code Form is subject to the terms of the Mozilla Public
7 * License, v. 2.0. If a copy of the MPL was not distributed with this
8 * file, you can obtain one at https://mozilla.org/MPL/2.0/.
9 *
10 * See the COPYRIGHT file distributed with this work for additional
11 * information regarding copyright ownership.
12 */
13
14 /*! \file */
15
16 #include <inttypes.h>
17 #include <sched.h> /* IWYU pragma: keep */
18 #include <setjmp.h>
19 #include <stdarg.h>
20 #include <stddef.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <time.h>
24 #include <unistd.h>
25
26 #define UNIT_TESTING
27 #include <cmocka.h>
28
29 #include <isc/parseint.h>
30 #include <isc/util.h>
31
32 #include <tests/isc.h>
33
34 /* Test for 32 bit overflow on 64 bit machines in isc_parse_uint32 */
35 ISC_RUN_TEST_IMPL(parse_overflow) {
36 isc_result_t result;
37 uint32_t output;
38
39 result = isc_parse_uint32(&output, "1234567890", 10);
40 assert_int_equal(ISC_R_SUCCESS, result);
41 assert_int_equal(1234567890, output);
42
43 result = isc_parse_uint32(&output, "123456789012345", 10);
44 assert_int_equal(ISC_R_RANGE, result);
45
46 result = isc_parse_uint32(&output, "12345678901234567890", 10);
47 assert_int_equal(ISC_R_RANGE, result);
48 }
49
50 ISC_TEST_LIST_START
51
52 ISC_TEST_ENTRY(parse_overflow)
53
54 ISC_TEST_LIST_END
55
56 ISC_TEST_MAIN