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