From: Mark Andrews Date: Wed, 4 Oct 2017 03:10:40 +0000 (+1100) Subject: 4752. [test] Add unit test for isc_net_pton. [RT #46171] X-Git-Tag: v9.12.0b1~99 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5fcdb09126d5723742813b2d25af19156b21370b;p=thirdparty%2Fbind9.git 4752. [test] Add unit test for isc_net_pton. [RT #46171] --- diff --git a/CHANGES b/CHANGES index bad33a357fe..ed28738e4ed 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,5 @@ +4752. [test] Add unit test for isc_net_pton. [RT #46171] + 4751. [func] "dnssec-signzone -S" can now automatically add parent synchronization records (CDS and CDNSKEY) according to key metadata set using the -Psync and -Dsync diff --git a/lib/isc/inet_ntop.c b/lib/isc/inet_ntop.c index a63f0587daa..21d5f4b7de4 100644 --- a/lib/isc/inet_ntop.c +++ b/lib/isc/inet_ntop.c @@ -173,7 +173,7 @@ inet_ntop6(const unsigned char *src, char *dst, size_t size) tp += strlen(tp); break; } - INSIST((tp - tmp) < sizeof(tmp)); + INSIST((size_t)(tp - tmp) < sizeof(tmp)); tp += snprintf(tp, sizeof(tmp) - (tp - tmp), "%x", words[i]); } /* Was it a trailing run of 0x00's? */ diff --git a/lib/isc/tests/Atffile b/lib/isc/tests/Atffile index 201a5045693..c22a19d66fb 100644 --- a/lib/isc/tests/Atffile +++ b/lib/isc/tests/Atffile @@ -9,6 +9,7 @@ tp: errno_test tp: file_test tp: hash_test tp: ht_test +tp: inet_ntop_test tp: lex_test tp: mem_test tp: netaddr_test diff --git a/lib/isc/tests/Makefile.in b/lib/isc/tests/Makefile.in index 70d9af69da7..c2cd5054227 100644 --- a/lib/isc/tests/Makefile.in +++ b/lib/isc/tests/Makefile.in @@ -27,20 +27,21 @@ LIBS = @LIBS@ @ATFLIBS@ OBJS = isctest.@O@ SRCS = isctest.c aes_test.c buffer_test.c counter_test.c \ errno_test.c file_test.c hash_test.c ht_test.c \ - lex_test.c mem_test.c netaddr_test.c parse_test.c \ - pool_test.c print_test.c queue_test.c radix_test.c \ - random_test.c regex_test.c result_test.c safe_test.c \ - sockaddr_test.c socket_test.c socket_test.c \ + inet_ntop_test.c lex_test.c mem_test.c netaddr_test.c \ + parse_test.c pool_test.c print_test.c queue_test.c \ + radix_test.c random_test.c regex_test.c result_test.c \ + safe_test.c sockaddr_test.c socket_test.c socket_test.c \ symtab_test.c task_test.c taskpool_test.c time_test.c SUBDIRS = TARGETS = aes_test@EXEEXT@ buffer_test@EXEEXT@ counter_test@EXEEXT@ \ errno_test@EXEEXT@ file_test@EXEEXT@ hash_test@EXEEXT@ \ - ht_test@EXEEXT@ lex_test@EXEEXT@ mem_test@EXEEXT@ \ - netaddr_test@EXEEXT@ parse_test@EXEEXT@ pool_test@EXEEXT@ \ - print_test@EXEEXT@ queue_test@EXEEXT@ radix_test@EXEEXT@ \ - random_test@EXEEXT@ regex_test@EXEEXT@ result_test@EXEEXT@ \ - safe_test@EXEEXT@ sockaddr_test@EXEEXT@ socket_test@EXEEXT@ \ + ht_test@EXEEXT@ inet_ntop_test@EXEEXT@ lex_test@EXEEXT@ \ + mem_test@EXEEXT@ netaddr_test@EXEEXT@ parse_test@EXEEXT@ \ + pool_test@EXEEXT@ print_test@EXEEXT@ queue_test@EXEEXT@ \ + radix_test@EXEEXT@ random_test@EXEEXT@ regex_test@EXEEXT@ \ + result_test@EXEEXT@ safe_test@EXEEXT@ \ + sockaddr_test@EXEEXT@ socket_test@EXEEXT@ \ socket_test@EXEEXT@ symtab_test@EXEEXT@ task_test@EXEEXT@ \ taskpool_test@EXEEXT@ time_test@EXEEXT@ @@ -74,6 +75,11 @@ ht_test@EXEEXT@: ht_test.@O@ ${ISCDEPLIBS} ${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \ ht_test.@O@ ${ISCLIBS} ${LIBS} +inet_ntop_test.c.@O@: ${top_srcdir}/lib/isc/ntop_test.c +inet_ntop_test@EXEEXT@: inet_ntop_test.@O@ ${ISCDEPLIBS} + ${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \ + inet_ntop_test.@O@ ${ISCLIBS} ${LIBS} + lex_test@EXEEXT@: lex_test.@O@ ${ISCDEPLIBS} ${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \ lex_test.@O@ ${ISCLIBS} ${LIBS} diff --git a/lib/isc/tests/inet_ntop_test.c b/lib/isc/tests/inet_ntop_test.c new file mode 100644 index 00000000000..b0d0eb0dbe5 --- /dev/null +++ b/lib/isc/tests/inet_ntop_test.c @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2014-2016 Internet Systems Consortium, Inc. ("ISC") + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include + +#include + +/* + * Force the prototype for isc_net_ntop to be declared. + */ +#include +#undef ISC_PLATFORM_NEEDNTOP +#define ISC_PLATFORM_NEEDNTOP +#include "../inet_ntop.c" + +ATF_TC(isc_net_ntop); +ATF_TC_HEAD(isc_net_ntop, tc) { + atf_tc_set_md_var(tc, "descr", "isc_net_ntop implementation"); +} +ATF_TC_BODY(isc_net_ntop, tc) { + char buf[sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")]; + int r; + size_t i; + unsigned char abuf[16]; + struct { + int family; + const char * address; + } testdata[] = { + { AF_INET, "0.0.0.0" }, + { AF_INET, "0.1.0.0" }, + { AF_INET, "0.0.2.0" }, + { AF_INET, "0.0.0.3" }, + { AF_INET, "255.255.255.255" }, + { AF_INET6, "::" }, + { AF_INET6, "::1.2.3.4" }, + { AF_INET6, "::ffff:1.2.3.4" }, + { AF_INET6, "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff" } + }; + + for (i = 0; i < sizeof(testdata)/sizeof(testdata[0]); i++) { + r = inet_pton(testdata[i].family, testdata[i].address, abuf); + ATF_REQUIRE_EQ_MSG(r, 1, "%s", testdata[i].address); + isc_net_ntop(testdata[i].family, abuf, buf, sizeof(buf)); + ATF_CHECK_STREQ(buf, testdata[i].address); + } +} + +/* + * Main + */ +ATF_TP_ADD_TCS(tp) { + ATF_TP_ADD_TC(tp, isc_net_ntop); + return (atf_no_error()); +}