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