summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn Strauss <gstrauss@gluelogic.com>2019-02-02 18:40:47 -0500
committerGlenn Strauss <gstrauss@gluelogic.com>2019-02-02 18:40:47 -0500
commit142e54b2a877397e64bc6bb658f71f1c3c1923d8 (patch)
tree75673cb8f9a0f05114e7cb9de13f3f64e6100a7a
parent40ded06b083e15930aedacdf544f8b0a0d99eed2 (diff)
downloadlighttpd1.4-142e54b2a877397e64bc6bb658f71f1c3c1923d8.tar.gz
lighttpd1.4-142e54b2a877397e64bc6bb658f71f1c3c1923d8.zip
[mod_evhost] handle IPv6 literal addr; add tests
-rw-r--r--src/mod_evhost.c14
-rw-r--r--src/t/test_mod_evhost.c54
2 files changed, 52 insertions, 16 deletions
diff --git a/src/mod_evhost.c b/src/mod_evhost.c
index ae707697..56450a82 100644
--- a/src/mod_evhost.c
+++ b/src/mod_evhost.c
@@ -197,6 +197,20 @@ static void mod_evhost_parse_host(buffer *key, array *host, buffer *authority) {
int first = 1;
int i;
+ /*if (ptr == authority->ptr) return;*//*(no authority checked earlier)*/
+
+ if (*authority->ptr == '[') { /* authority is IPv6 literal address */
+ colon = ptr;
+ if (ptr[-1] != ']') {
+ do { --ptr; } while (ptr > authority->ptr && ptr[-1] != ']');
+ if (*ptr != ':') return; /*(should not happen for valid authority)*/
+ colon = ptr;
+ }
+ ptr = authority->ptr;
+ array_insert_key_value(host,CONST_STR_LEN("%0"),ptr,colon-ptr);
+ return;
+ }
+
/* first, find the domain + tld */
for(; ptr > authority->ptr; --ptr) {
if(*ptr == '.') {
diff --git a/src/t/test_mod_evhost.c b/src/t/test_mod_evhost.c
index 0600479e..9bffb3da 100644
--- a/src/t/test_mod_evhost.c
+++ b/src/t/test_mod_evhost.c
@@ -22,16 +22,30 @@ static void test_mod_evhost_plugin_config_free(plugin_config *s) {
free(s);
}
+struct ttt {
+ const char *pattern;
+ size_t plen;
+ const char *expect;
+ size_t elen;
+};
+
+static void test_mod_evhost_build_doc_root_path_loop(struct ttt *tt, size_t nelts, buffer *authority, buffer *b, array *a) {
+ for (size_t i = 0; i < nelts; ++i) {
+ struct ttt *t = tt+i;
+ plugin_config *s = test_mod_evhost_plugin_config_init();
+ buffer_copy_string_len(s->path_pieces_raw, t->pattern, t->plen);
+ assert(0 == mod_evhost_parse_pattern(s));
+ mod_evhost_build_doc_root_path(b, a, authority, s->path_pieces, s->len);
+ assert(buffer_is_equal_string(b, t->expect, t->elen));
+ test_mod_evhost_plugin_config_free(s);
+ }
+}
+
static void test_mod_evhost_build_doc_root_path(void) {
- buffer *authority = buffer_init_string("host.example.org");
+ buffer *authority = buffer_init();
buffer *b = buffer_init();
array *a = array_init();
- struct ttt {
- const char *pattern;
- size_t plen;
- const char *expect;
- size_t elen;
- } tt[] = {
+ struct ttt tt1[] = { /* "host.example.org" */
/* correct pattern not using dot notation */
{ CONST_STR_LEN("/web/%3/"),
CONST_STR_LEN("/web/host/") }
@@ -44,17 +58,25 @@ static void test_mod_evhost_build_doc_root_path(void) {
/* other pattern 2 */
,{ CONST_STR_LEN("/web/%3.\1/"),
CONST_STR_LEN("/web/host.\1/") }
+ ,{ CONST_STR_LEN("/web/%0/"),
+ CONST_STR_LEN("/web/example.org/") }
+ }, tt2[] = { /* "example" */
+ { CONST_STR_LEN("/web/%0"),
+ CONST_STR_LEN("/web/example/") }
+ }, tt3[] = { /* "[::1]:80" */
+ { CONST_STR_LEN("/web/%0"),
+ CONST_STR_LEN("/web/[::1]/") }
};
- for (size_t i = 0; i < sizeof(tt)/sizeof(tt[0]); ++i) {
- struct ttt *t = tt+i;
- plugin_config *s = test_mod_evhost_plugin_config_init();
- buffer_copy_string_len(s->path_pieces_raw, t->pattern, t->plen);
- assert(0 == mod_evhost_parse_pattern(s));
- mod_evhost_build_doc_root_path(b, a, authority, s->path_pieces, s->len);
- assert(buffer_is_equal_string(b, t->expect, t->elen));
- test_mod_evhost_plugin_config_free(s);
- }
+ array_reset_data_strings(a);
+ buffer_copy_string_len(authority, CONST_STR_LEN("host.example.org"));
+ test_mod_evhost_build_doc_root_path_loop(tt1, sizeof(tt1)/sizeof(tt1[0]), authority, b, a);
+ array_reset_data_strings(a);
+ buffer_copy_string_len(authority, CONST_STR_LEN("example"));
+ test_mod_evhost_build_doc_root_path_loop(tt2, sizeof(tt2)/sizeof(tt2[0]), authority, b, a);
+ array_reset_data_strings(a);
+ buffer_copy_string_len(authority, CONST_STR_LEN("[::1]:80"));
+ test_mod_evhost_build_doc_root_path_loop(tt3, sizeof(tt3)/sizeof(tt3[0]), authority, b, a);
buffer_free(authority);
buffer_free(b);