diff options
| author | Dag-Erling Smørgrav <des@FreeBSD.org> | 2013-04-05 09:06:26 +0000 |
|---|---|---|
| committer | Dag-Erling Smørgrav <des@FreeBSD.org> | 2013-04-05 09:06:26 +0000 |
| commit | 697291b66c481c617cf9875497e2189bc4a4b096 (patch) | |
| tree | 5c98c370bedd1d0b4cc456b94e1f7a8ceb080bff /testcode | |
| parent | afb79913ce00d885b8b43f7478e1e054edadb567 (diff) | |
Notes
Diffstat (limited to 'testcode')
| -rw-r--r-- | testcode/fake_event.c | 3 | ||||
| -rw-r--r-- | testcode/ldns-testpkts.c | 43 | ||||
| -rw-r--r-- | testcode/ldns-testpkts.h | 8 | ||||
| -rw-r--r-- | testcode/replay.c | 4 | ||||
| -rw-r--r-- | testcode/testbound.c | 2 | ||||
| -rw-r--r-- | testcode/unitmain.c | 32 | ||||
| -rw-r--r-- | testcode/unitverify.c | 18 |
7 files changed, 75 insertions, 35 deletions
diff --git a/testcode/fake_event.c b/testcode/fake_event.c index 26dfaa8b068b..180ff30697e2 100644 --- a/testcode/fake_event.c +++ b/testcode/fake_event.c @@ -1041,14 +1041,13 @@ struct serviced_query* outnet_serviced_query(struct outside_network* outnet, int ATTR_UNUSED(tcp_upstream), int ATTR_UNUSED(ssl_upstream), struct sockaddr_storage* addr, socklen_t addrlen, uint8_t* zone, size_t zonelen, comm_point_callback_t* callback, void* callback_arg, - ldns_buffer* ATTR_UNUSED(buff), int (*arg_compare)(void*,void*)) + ldns_buffer* ATTR_UNUSED(buff)) { struct replay_runtime* runtime = (struct replay_runtime*)outnet->base; struct fake_pending* pend = (struct fake_pending*)calloc(1, sizeof(struct fake_pending)); char z[256]; ldns_status status; - (void)arg_compare; log_assert(pend); log_nametypeclass(VERB_OPS, "pending serviced query", qname, qtype, qclass); diff --git a/testcode/ldns-testpkts.c b/testcode/ldns-testpkts.c index d8139511ab5c..be94eb2fe438 100644 --- a/testcode/ldns-testpkts.c +++ b/testcode/ldns-testpkts.c @@ -323,7 +323,7 @@ data_buffer2wire(ldns_buffer *data_buffer) uint8_t *hexbuf; int hexbufpos = 0; size_t wirelen; - uint8_t *data_wire = (uint8_t *) ldns_buffer_export(data_buffer); + uint8_t *data_wire = (uint8_t *) ldns_buffer_begin(data_buffer); uint8_t *wire = LDNS_XMALLOC(uint8_t, LDNS_MAX_PACKETLEN); hexbuf = LDNS_XMALLOC(uint8_t, LDNS_MAX_PACKETLEN); @@ -340,6 +340,12 @@ data_buffer2wire(ldns_buffer *data_buffer) (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F') ) { + if (hexbufpos >= LDNS_MAX_PACKETLEN) { + error("buffer overflow"); + LDNS_FREE(hexbuf); + return 0; + + } hexbuf[hexbufpos] = (uint8_t) c; hexbufpos++; } else if (c == ';') { @@ -354,14 +360,14 @@ data_buffer2wire(ldns_buffer *data_buffer) } break; case 2: + if (hexbufpos >= LDNS_MAX_PACKETLEN) { + error("buffer overflow"); + LDNS_FREE(hexbuf); + return 0; + } hexbuf[hexbufpos] = (uint8_t) c; hexbufpos++; break; - default: - error("unknown state while reading"); - LDNS_FREE(hexbuf); - return 0; - break; } } @@ -371,6 +377,11 @@ data_buffer2wire(ldns_buffer *data_buffer) /* lenient mode: length must be multiple of 2 */ if (hexbufpos % 2 != 0) { + if (hexbufpos >= LDNS_MAX_PACKETLEN) { + error("buffer overflow"); + LDNS_FREE(hexbuf); + return 0; + } hexbuf[hexbufpos] = (uint8_t) '0'; hexbufpos++; } @@ -415,7 +426,7 @@ get_origin(const char* name, int lineno, ldns_rdf** origin, char* parse) /* Reads one entry from file. Returns entry or NULL on error. */ struct entry* read_entry(FILE* in, const char* name, int *lineno, uint32_t* default_ttl, - ldns_rdf** origin, ldns_rdf** prev_rr) + ldns_rdf** origin, ldns_rdf** prev_rr, int skip_whitespace) { struct entry* current = NULL; char line[MAX_LINE]; @@ -485,7 +496,10 @@ read_entry(FILE* in, const char* name, int *lineno, uint32_t* default_ttl, reading_hex = false; cur_reply->reply_from_hex = data_buffer2wire(hex_data_buffer); ldns_buffer_free(hex_data_buffer); + hex_data_buffer = NULL; } else if(str_keyword(&parse, "ENTRY_END")) { + if (hex_data_buffer) + ldns_buffer_free(hex_data_buffer); return current; } else if(reading_hex) { ldns_buffer_printf(hex_data_buffer, line); @@ -493,14 +507,17 @@ read_entry(FILE* in, const char* name, int *lineno, uint32_t* default_ttl, /* it must be a RR, parse and add to packet. */ ldns_rr* n = NULL; ldns_status status; + char* rrstr = line; + if (skip_whitespace) + rrstr = parse; if(add_section == LDNS_SECTION_QUESTION) status = ldns_rr_new_question_frm_str( - &n, parse, *origin, prev_rr); - else status = ldns_rr_new_frm_str(&n, parse, + &n, rrstr, *origin, prev_rr); + else status = ldns_rr_new_frm_str(&n, rrstr, *default_ttl, *origin, prev_rr); if(status != LDNS_STATUS_OK) error("%s line %d:\n\t%s: %s", name, *lineno, - ldns_get_errorstr_by_id(status), parse); + ldns_get_errorstr_by_id(status), rrstr); ldns_pkt_push_rr(cur_reply->reply, add_section, n); } @@ -518,7 +535,7 @@ read_entry(FILE* in, const char* name, int *lineno, uint32_t* default_ttl, /* reads the canned reply file and returns a list of structs */ struct entry* -read_datafile(const char* name) +read_datafile(const char* name, int skip_whitespace) { struct entry* list = NULL; struct entry* last = NULL; @@ -535,7 +552,7 @@ read_datafile(const char* name) } while((current = read_entry(in, name, &lineno, &default_ttl, - &origin, &prev_rr))) + &origin, &prev_rr, skip_whitespace))) { if(last) last->next = current; @@ -815,7 +832,7 @@ handle_query(uint8_t* inbuf, ssize_t inlen, struct entry* entries, int* count, /* still try to adjust ID */ answer_size = ldns_buffer_capacity(p->reply_from_hex); outbuf = LDNS_XMALLOC(uint8_t, answer_size); - memcpy(outbuf, ldns_buffer_export(p->reply_from_hex), answer_size); + memcpy(outbuf, ldns_buffer_begin(p->reply_from_hex), answer_size); if(entry->copy_id) { ldns_write_uint16(outbuf, ldns_pkt_id(query_pkt)); diff --git a/testcode/ldns-testpkts.h b/testcode/ldns-testpkts.h index 59e428952759..2431e2e1e17d 100644 --- a/testcode/ldns-testpkts.h +++ b/testcode/ldns-testpkts.h @@ -197,8 +197,10 @@ struct entry { /** * reads the canned reply file and returns a list of structs * does an exit on error. + * @param name: name of the file to read. + * @param skip_whitespace: skip leftside whitespace. */ -struct entry* read_datafile(const char* name); +struct entry* read_datafile(const char* name, int skip_whitespace); /** * Delete linked list of entries. @@ -217,10 +219,12 @@ void delete_entry(struct entry* list); * later it stores the $ORIGIN value last seen. Often &NULL or the zone * name on first call. * @param prev_rr: previous rr name for correcter parsing. &NULL on first call. + * @param skip_whitespace: skip leftside whitespace. * @return: The entry read (malloced) or NULL if no entry could be read. */ struct entry* read_entry(FILE* in, const char* name, int *lineno, - uint32_t* default_ttl, ldns_rdf** origin, ldns_rdf** prev_rr); + uint32_t* default_ttl, ldns_rdf** origin, ldns_rdf** prev_rr, + int skip_whitespace); /** * finds entry in list, or returns NULL. diff --git a/testcode/replay.c b/testcode/replay.c index 3d3aa01a08d1..2ce647da1197 100644 --- a/testcode/replay.c +++ b/testcode/replay.c @@ -193,7 +193,7 @@ replay_range_read(char* remain, FILE* in, const char* name, int* lineno, /* set position before line; read entry */ (*lineno)--; fseeko(in, pos, SEEK_SET); - entry = read_entry(in, name, lineno, ttl, or, prev); + entry = read_entry(in, name, lineno, ttl, or, prev, 1); if(!entry) fatal_exit("%d: bad entry", *lineno); entry->next = NULL; @@ -393,7 +393,7 @@ replay_moment_read(char* remain, FILE* in, const char* name, int* lineno, } if(readentry) { - mom->match = read_entry(in, name, lineno, ttl, or, prev); + mom->match = read_entry(in, name, lineno, ttl, or, prev, 1); if(!mom->match) { free(mom); return NULL; diff --git a/testcode/testbound.c b/testcode/testbound.c index 05982849cc29..6e88edf22e62 100644 --- a/testcode/testbound.c +++ b/testcode/testbound.c @@ -281,7 +281,7 @@ main(int argc, char* argv[]) printf("selftest successful\n"); exit(0); case '2': -#if defined(HAVE_EVP_SHA256) && defined(USE_SHA2) +#if (defined(HAVE_EVP_SHA256) || defined(HAVE_NSS)) && defined(USE_SHA2) printf("SHA256 supported\n"); exit(0); #else diff --git a/testcode/unitmain.c b/testcode/unitmain.c index f381b0b03e23..122f09b86149 100644 --- a/testcode/unitmain.c +++ b/testcode/unitmain.c @@ -55,6 +55,12 @@ #ifdef HAVE_OPENSSL_ENGINE_H #include <openssl/engine.h> #endif + +#ifdef HAVE_NSS +/* nss3 */ +#include "nss.h" +#endif + #include <ldns/ldns.h> #include "util/log.h" #include "testcode/unitmain.h" @@ -555,13 +561,18 @@ main(int argc, char* argv[]) return 1; } printf("Start of %s unit test.\n", PACKAGE_STRING); +#ifdef HAVE_SSL ERR_load_crypto_strings(); -#ifdef HAVE_OPENSSL_CONFIG +# ifdef HAVE_OPENSSL_CONFIG OPENSSL_config("unbound"); -#endif -#ifdef USE_GOST +# endif +# ifdef USE_GOST (void)ldns_key_EVP_load_gost_id(); -#endif +# endif +#elif defined(HAVE_NSS) + if(NSS_NoDB_Init(".") != SECSuccess) + fatal_exit("could not init NSS"); +#endif /* HAVE_SSL or HAVE_NSS*/ checklock_start(); neg_test(); rnd_test(); @@ -579,18 +590,23 @@ main(int argc, char* argv[]) msgparse_test(); checklock_stop(); printf("%d checks ok.\n", testcount); -#if defined(USE_GOST) && defined(HAVE_LDNS_KEY_EVP_UNLOAD_GOST) +#ifdef HAVE_SSL +# if defined(USE_GOST) && defined(HAVE_LDNS_KEY_EVP_UNLOAD_GOST) ldns_key_EVP_unload_gost(); -#endif -#ifdef HAVE_OPENSSL_CONFIG +# endif +# ifdef HAVE_OPENSSL_CONFIG EVP_cleanup(); ENGINE_cleanup(); CONF_modules_free(); -#endif +# endif CRYPTO_cleanup_all_ex_data(); ERR_remove_state(0); ERR_free_strings(); RAND_cleanup(); +#elif defined(HAVE_NSS) + if(NSS_Shutdown() != SECSuccess) + fatal_exit("could not shutdown NSS"); +#endif /* HAVE_SSL or HAVE_NSS */ #ifdef HAVE_PTHREAD /* dlopen frees its thread specific state */ pthread_exit(NULL); diff --git a/testcode/unitverify.c b/testcode/unitverify.c index 2bc842c75374..d3fbf25f5312 100644 --- a/testcode/unitverify.c +++ b/testcode/unitverify.c @@ -42,6 +42,7 @@ #include "util/log.h" #include "testcode/unitmain.h" #include "validator/val_sigcrypt.h" +#include "validator/val_secalgo.h" #include "validator/val_nsec.h" #include "validator/val_nsec3.h" #include "validator/validator.h" @@ -297,7 +298,7 @@ verifytest_file(const char* fname, const char* at_date) struct alloc_cache alloc; ldns_buffer* buf = ldns_buffer_new(65535); struct entry* e; - struct entry* list = read_datafile(fname); + struct entry* list = read_datafile(fname, 1); struct module_env env; struct val_env ve; uint32_t now = time(NULL); @@ -341,7 +342,7 @@ dstest_file(const char* fname) struct alloc_cache alloc; ldns_buffer* buf = ldns_buffer_new(65535); struct entry* e; - struct entry* list = read_datafile(fname); + struct entry* list = read_datafile(fname, 1); struct module_env env; if(!list) @@ -474,7 +475,7 @@ nsec3_hash_test(const char* fname) struct alloc_cache alloc; ldns_buffer* buf = ldns_buffer_new(65535); struct entry* e; - struct entry* list = read_datafile(fname); + struct entry* list = read_datafile(fname, 1); if(!list) fatal_exit("could not read %s: %s", fname, strerror(errno)); @@ -505,12 +506,12 @@ verify_test(void) verifytest_file("testdata/test_signatures.6", "20080416005004"); verifytest_file("testdata/test_signatures.7", "20070829144150"); verifytest_file("testdata/test_signatures.8", "20070829144150"); -#if defined(HAVE_EVP_SHA256) && defined(USE_SHA2) +#if (defined(HAVE_EVP_SHA256) || defined(HAVE_NSS)) && defined(USE_SHA2) verifytest_file("testdata/test_sigs.rsasha256", "20070829144150"); verifytest_file("testdata/test_sigs.sha1_and_256", "20070829144150"); verifytest_file("testdata/test_sigs.rsasha256_draft", "20090101000000"); #endif -#if defined(HAVE_EVP_SHA512) && defined(USE_SHA2) +#if (defined(HAVE_EVP_SHA512) || defined(HAVE_NSS)) && defined(USE_SHA2) verifytest_file("testdata/test_sigs.rsasha512_draft", "20070829144150"); #endif verifytest_file("testdata/test_sigs.hinfo", "20090107100022"); @@ -521,8 +522,11 @@ verify_test(void) else printf("Warning: skipped GOST, openssl does not provide gost.\n"); #endif #ifdef USE_ECDSA - verifytest_file("testdata/test_sigs.ecdsa_p256", "20100908100439"); - verifytest_file("testdata/test_sigs.ecdsa_p384", "20100908100439"); + /* test for support in case we use libNSS and ECC is removed */ + if(dnskey_algo_id_is_supported(LDNS_ECDSAP256SHA256)) { + verifytest_file("testdata/test_sigs.ecdsa_p256", "20100908100439"); + verifytest_file("testdata/test_sigs.ecdsa_p384", "20100908100439"); + } dstest_file("testdata/test_ds.sha384"); #endif dstest_file("testdata/test_ds.sha1"); |
