From a66bad688b46d585b85bc86cd58bfbf339e0f4ad Mon Sep 17 00:00:00 2001 From: Wouter Wijngaards Date: Wed, 6 Jan 2010 10:55:14 +0000 Subject: [PATCH] Fix bug#291 and unit test spruced up. git-svn-id: file:///svn/unbound/trunk@1948 be551aaa-1e26-0410-a405-d3ace91eadb9 --- doc/Changelog | 1 + testcode/unitanchor.c | 1 + testcode/unitdname.c | 62 +++++++++++++++++++++++++++++++++++++++++ testcode/unitlruhash.c | 2 +- testcode/unitmain.c | 22 ++++++++++++++- testcode/unitmain.h | 5 ++++ testcode/unitmsgparse.c | 2 +- testcode/unitneg.c | 1 + testcode/unitslabhash.c | 2 +- testcode/unitverify.c | 2 +- util/data/dname.c | 2 +- 11 files changed, 96 insertions(+), 6 deletions(-) diff --git a/doc/Changelog b/doc/Changelog index 64d0d9ad8..63291b77e 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,5 +1,6 @@ 6 January 2010: Wouter - iana portlist updated. + - bug#291: DNS wireformat max is 255. dname_valid allowed 256 length. 1 January 2010: Wouter - iana portlist updated. diff --git a/testcode/unitanchor.c b/testcode/unitanchor.c index ea090bc7e..ac7b9d5b5 100644 --- a/testcode/unitanchor.c +++ b/testcode/unitanchor.c @@ -124,6 +124,7 @@ void anchors_test() { ldns_buffer* buff = ldns_buffer_new(65800); struct val_anchors* a; + unit_show_feature("trust anchor store"); unit_assert(a = anchors_create()); ldns_buffer_flip(buff); test_anchor_empty(a); diff --git a/testcode/unitdname.c b/testcode/unitdname.c index 24b52b783..3c3d71ac8 100644 --- a/testcode/unitdname.c +++ b/testcode/unitdname.c @@ -64,6 +64,7 @@ dname_to_buf(ldns_buffer* b, const char* str) static void dname_test_qdl(ldns_buffer* buff) { + unit_show_func("util/data/dname.c", "query_dname_len"); unit_assert( query_dname_len(buff) == 0); unit_assert( query_dname_len(dname_to_buf(buff, ".")) == 1 ); unit_assert( query_dname_len(dname_to_buf(buff, "bla.foo.")) == 9 ); @@ -75,6 +76,7 @@ dname_test_qdl(ldns_buffer* buff) static void dname_test_qdtl(ldns_buffer* buff) { + unit_show_func("util/data/dname.c", "query_dname_tolower"); ldns_buffer_write_at(buff, 0, "\012abCDeaBCde\003cOm\000", 16); query_dname_tolower(ldns_buffer_begin(buff)); unit_assert( memcmp(ldns_buffer_begin(buff), @@ -98,6 +100,7 @@ dname_test_qdtl(ldns_buffer* buff) static void dname_test_query_dname_compare() { + unit_show_func("util/data/dname.c", "query_dname_compare"); unit_assert(query_dname_compare((uint8_t*)"", (uint8_t*)"") == 0); unit_assert(query_dname_compare((uint8_t*)"\001a", (uint8_t*)"\001a") == 0); @@ -127,6 +130,7 @@ dname_test_query_dname_compare() static void dname_test_count_labels() { + unit_show_func("util/data/dname.c", "dname_count_labels"); unit_assert(dname_count_labels((uint8_t*)"") == 1); unit_assert(dname_count_labels((uint8_t*)"\003com") == 2); unit_assert(dname_count_labels((uint8_t*)"\003org") == 2); @@ -140,6 +144,7 @@ static void dname_test_count_size_labels() { size_t sz = 0; + unit_show_func("util/data/dname.c", "dname_count_size_labels"); unit_assert(dname_count_size_labels((uint8_t*)"", &sz) == 1); unit_assert(sz == 1); unit_assert(dname_count_size_labels((uint8_t*)"\003com", &sz) == 2); @@ -159,6 +164,7 @@ dname_test_count_size_labels() static void dname_test_pkt_dname_len(ldns_buffer* buff) { + unit_show_func("util/data/dname.c", "pkt_dname_len"); ldns_buffer_clear(buff); ldns_buffer_write(buff, "\000", 1); ldns_buffer_flip(buff); @@ -265,6 +271,7 @@ static void dname_test_dname_lab_cmp() { int ml = 0; /* number of labels that matched exactly */ + unit_show_func("util/data/dname.c", "dname_lab_cmp"); /* test for equality succeeds */ unit_assert(dname_lab_cmp((uint8_t*)"", 1, (uint8_t*)"", 1, &ml) == 0); @@ -365,6 +372,7 @@ dname_test_dname_lab_cmp() static void dname_test_subdomain() { + unit_show_func("util/data/dname.c", "dname_subdomain"); unit_assert(dname_subdomain_c( (uint8_t*)"", (uint8_t*)"")); @@ -401,6 +409,7 @@ dname_test_subdomain() static void dname_test_strict_subdomain() { + unit_show_func("util/data/dname.c", "dname_strict_subdomain"); unit_assert(!dname_strict_subdomain( (uint8_t*)"", 1, (uint8_t*)"", 1)); @@ -437,6 +446,7 @@ dname_test_strict_subdomain() static void dname_test_isroot() { + unit_show_func("util/data/dname.c", "dname_isroot"); unit_assert(dname_is_root((uint8_t*)"\000")); unit_assert(!dname_is_root((uint8_t*)"\001a\000")); unit_assert(!dname_is_root((uint8_t*)"\005abvcd\003com\000")); @@ -452,6 +462,7 @@ dname_test_removelabel() uint8_t* orig = (uint8_t*)"\007example\003com\000"; uint8_t* n = orig; size_t l = 13; + unit_show_func("util/data/dname.c", "dname_remove_label"); dname_remove_label(&n, &l); unit_assert( n == orig+8 ); unit_assert( l == 5 ); @@ -467,6 +478,7 @@ dname_test_removelabel() static void dname_test_sigcount() { + unit_show_func("util/data/dname.c", "dname_signame_label_count"); unit_assert(dname_signame_label_count((uint8_t*)"\000") == 0); unit_assert(dname_signame_label_count((uint8_t*)"\001*\000") == 0); unit_assert(dname_signame_label_count((uint8_t*)"\003xom\000") == 1); @@ -486,6 +498,7 @@ dname_test_sigcount() static void dname_test_iswild() { + unit_show_func("util/data/dname.c", "dname_iswild"); unit_assert( !dname_is_wild((uint8_t*)"\000") ); unit_assert( dname_is_wild((uint8_t*)"\001*\000") ); unit_assert( !dname_is_wild((uint8_t*)"\003net\000") ); @@ -496,6 +509,7 @@ dname_test_iswild() static void dname_test_canoncmp() { + unit_show_func("util/data/dname.c", "dname_canonical_compare"); /* equality */ unit_assert( dname_canonical_compare( (uint8_t*)"\000", @@ -715,6 +729,7 @@ dname_test_canoncmp() static void dname_test_topdomain() { + unit_show_func("util/data/dname.c", "dname_get_shared_topdomain"); unit_assert( query_dname_compare( dname_get_shared_topdomain( (uint8_t*)"", @@ -732,6 +747,52 @@ dname_test_topdomain() (uint8_t*)"\007example\003com") == 0); } +/** Test dname_valid */ +static void +dname_test_valid() +{ + unit_show_func("util/data/dname.c", "dname_valid"); + unit_assert( dname_valid( + (uint8_t*)"\003www\007example\003com", 255) == 17); + unit_assert( dname_valid((uint8_t*)"", 255) == 1); + unit_assert( dname_valid( (uint8_t*) + "\020a1cdef5555544444" + "\020a2cdef5555544444" + "\020a3cdef5555544444" + "\020a4cdef5555544444" + "\020a5cdef5555544444" + "\020a6cdef5555544444" + "\020a7cdef5555544444" + "\020a8cdef5555544444" + "\020a9cdef5555544444" + "\020aAcdef5555544444" + "\020aBcdef5555544444" + "\020aCcdef5555544444" + "\020aDcdef5555544444" + "\020aEcdef5555544444" /* 238 up to here */ + "\007aabbccd" /* 246 up to here */ + "\007example\000" /* 255 to here */ + , 255) == 255); + unit_assert( dname_valid( (uint8_t*) + "\020a1cdef5555544444" + "\020a2cdef5555544444" + "\020a3cdef5555544444" + "\020a4cdef5555544444" + "\020a5cdef5555544444" + "\020a6cdef5555544444" + "\020a7cdef5555544444" + "\020a8cdef5555544444" + "\020a9cdef5555544444" + "\020aAcdef5555544444" + "\020aBcdef5555544444" + "\020aCcdef5555544444" + "\020aDcdef5555544444" + "\020aEcdef5555544444" /* 238 up to here */ + "\007aabbccd" /* 246 up to here */ + "\010exampleX\000" /* 256 to here */ + , 4096) == 0); +} + void dname_test() { ldns_buffer* buff = ldns_buffer_new(65800); @@ -751,5 +812,6 @@ void dname_test() dname_test_iswild(); dname_test_canoncmp(); dname_test_topdomain(); + dname_test_valid(); ldns_buffer_free(buff); } diff --git a/testcode/unitlruhash.c b/testcode/unitlruhash.c index 13fa3c3d5..048ed5531 100644 --- a/testcode/unitlruhash.c +++ b/testcode/unitlruhash.c @@ -482,7 +482,7 @@ void lruhash_test() /* start very very small array, so it can do lots of table_grow() */ /* also small in size so that reclaim has to be done quickly. */ struct lruhash* table ; - printf("lruhash test\n"); + unit_show_feature("lruhash"); table = lruhash_create(2, 8192, test_slabhash_sizefunc, test_slabhash_compfunc, test_slabhash_delkey, test_slabhash_deldata, NULL); diff --git a/testcode/unitmain.c b/testcode/unitmain.c index eead05431..2204dff67 100644 --- a/testcode/unitmain.c +++ b/testcode/unitmain.c @@ -54,6 +54,7 @@ alloc_test() { struct alloc_cache major, minor1, minor2; int i; + unit_show_feature("alloc_special_obtain"); alloc_init(&major, NULL, 0); alloc_init(&minor1, &major, 0); alloc_init(&minor2, &major, 1); @@ -125,6 +126,7 @@ net_test() "\377\377\377\377", "\377\377\377\377", }; + unit_show_func("util/net_help.c", "str_is_ip6"); unit_assert( str_is_ip6("::") ); unit_assert( str_is_ip6("::1") ); unit_assert( str_is_ip6("2001:7b8:206:1:240:f4ff:fe37:8810") ); @@ -133,6 +135,7 @@ net_test() unit_assert( !str_is_ip6("213.154.224.12") ); unit_assert( !str_is_ip6("213.154.224.255") ); unit_assert( !str_is_ip6("255.255.255.0") ); + unit_show_func("util/net_help.c", "is_pow2"); unit_assert( is_pow2(0) ); unit_assert( is_pow2(1) ); unit_assert( is_pow2(2) ); @@ -155,6 +158,7 @@ net_test() unit_assert( !is_pow2(259) ); /* test addr_mask */ + unit_show_func("util/net_help.c", "addr_mask"); if(1) { struct sockaddr_in a4; struct sockaddr_in6 a6; @@ -183,6 +187,7 @@ net_test() } /* test addr_in_common */ + unit_show_func("util/net_help.c", "addr_in_common"); if(1) { struct sockaddr_in a4, b4; struct sockaddr_in6 a6, b6; @@ -239,6 +244,7 @@ net_test() } } /* test addr_is_ip4mapped */ + unit_show_func("util/net_help.c", "addr_is_ip4mapped"); if(1) { struct sockaddr_storage a; socklen_t l = (socklen_t)sizeof(a); @@ -269,6 +275,7 @@ static void config_memsize_test() { size_t v = 0; + unit_show_func("util/config_file.c", "cfg_parse_memsize"); if(0) { /* these emit errors */ unit_assert( cfg_parse_memsize("", &v) == 0); @@ -309,6 +316,7 @@ rtt_test() int init = 376; int i; struct rtt_info r; + unit_show_func("util/rtt.c", "rtt_timeout"); rtt_init(&r); /* initial value sensible */ unit_assert( rtt_timeout(&r) == init ); @@ -346,6 +354,7 @@ infra_test() int init = 376; int dlame, rlame, alame, olame; + unit_show_feature("infra cache"); unit_assert(ipstrtoaddr("127.0.0.1", 53, &one, &onelen)); slab = infra_create(cfg); @@ -403,6 +412,7 @@ rnd_test() struct ub_randstate* r; int num = 100, i; long int a[100]; + unit_show_feature("ub_random"); unit_assert( (r = ub_initstate((unsigned)time(NULL), NULL)) ); for(i=0; i LDNS_MAX_DOMAINLEN) + if(len >= LDNS_MAX_DOMAINLEN) return 0; /* too long */ if(len > maxlen) return 0; /* does not fit in memory allocation */ -- 2.47.2