From c8167234fa9bf55c0ff80bcedc2855b58c9519ee Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sat, 16 Feb 2013 02:33:16 +0900 Subject: [PATCH] shrpx: Fix bug in certificate lookup --- src/shrpx_ssl.cc | 2 ++ src/shrpx_ssl_test.cc | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/shrpx_ssl.cc b/src/shrpx_ssl.cc index 6baa9fac..26cc392a 100644 --- a/src/shrpx_ssl.cc +++ b/src/shrpx_ssl.cc @@ -600,6 +600,8 @@ void cert_lookup_tree_add_cert(CertLookupTree *lt, CertNode *node, new_node->first = i; new_node->last = cn->last; new_node->wildcard_certs.swap(cn->wildcard_certs); + new_node->next.swap(cn->next); + cn->next.push_back(new_node); cn->last = i; diff --git a/src/shrpx_ssl_test.cc b/src/shrpx_ssl_test.cc index 26b99824..daec697d 100644 --- a/src/shrpx_ssl_test.cc +++ b/src/shrpx_ssl_test.cc @@ -94,6 +94,24 @@ void test_shrpx_ssl_create_lookup_tree(void) for(int i = 0; i < num; ++i) { SSL_CTX_free(ctxs[i]); } + + SSL_CTX *ctxs2[] = {SSL_CTX_new(TLSv1_method()), + SSL_CTX_new(TLSv1_method()), + SSL_CTX_new(TLSv1_method())}; + const char *names[] = { "rab", "zab", "zzub" }; + num = sizeof(ctxs2)/sizeof(ctxs2[0]); + tree = ssl::cert_lookup_tree_new(); + for(int i = 0; i < num; ++i) { + ssl::cert_lookup_tree_add_cert(tree, ctxs2[i], names[i], strlen(names[i])); + } + for(int i = 0; i < num; ++i) { + CU_ASSERT(ctxs2[i] == ssl::cert_lookup_tree_lookup(tree, names[i], + strlen(names[i]))); + } + ssl::cert_lookup_tree_del(tree); + for(int i = 0; i < num; ++i) { + SSL_CTX_free(ctxs2[i]); + } } void test_shrpx_ssl_cert_lookup_tree_add_cert_from_file(void)