update: added CRLF and CR support for resolv.conf parser. added more

tests.
pull/348/head
Datong Sun 7 years ago
parent 34adaa8ac8
commit 44ebee2215
No known key found for this signature in database
GPG Key ID: 1908AE626BFCE242

@ -1,5 +1,5 @@
diff --git a/src/core/ngx_resolver.c b/src/core/ngx_resolver.c diff --git a/src/core/ngx_resolver.c b/src/core/ngx_resolver.c
index cd55520c..06d1c461 100644 index cd55520c..efa9ef55 100644
--- a/src/core/ngx_resolver.c --- a/src/core/ngx_resolver.c
+++ b/src/core/ngx_resolver.c +++ b/src/core/ngx_resolver.c
@@ -15,6 +15,9 @@ @@ -15,6 +15,9 @@
@ -12,7 +12,7 @@ index cd55520c..06d1c461 100644
typedef struct { typedef struct {
u_char ident_hi; u_char ident_hi;
@@ -131,6 +134,143 @@ static ngx_resolver_node_t *ngx_resolver_lookup_addr6(ngx_resolver_t *r, @@ -131,6 +134,142 @@ static ngx_resolver_node_t *ngx_resolver_lookup_addr6(ngx_resolver_t *r,
#endif #endif
@ -101,7 +101,7 @@ index cd55520c..06d1c461 100644
+ address = i; + address = i;
+ } + }
+ +
+ if (buf[i] == LF || i == n - 1) { + if (buf[i] == CR || buf[i] == LF || i == n - 1) {
+ ngx_memzero(&u, sizeof(ngx_url_t)); + ngx_memzero(&u, sizeof(ngx_url_t));
+ +
+ u.url.data = buf + address; + u.url.data = buf + address;
@ -132,14 +132,13 @@ index cd55520c..06d1c461 100644
+ rec[j].resolver = r; + rec[j].resolver = r;
+ } + }
+ +
+ address = 0;
+ state = sw_nameserver; + state = sw_nameserver;
+ } + }
+ +
+ break; + break;
+ +
+ case sw_skip: + case sw_skip:
+ if (buf[i] == LF) { + if (buf[i] == CR || buf[i] == LF) {
+ state = sw_nameserver; + state = sw_nameserver;
+ } + }
+ +
@ -156,7 +155,7 @@ index cd55520c..06d1c461 100644
ngx_resolver_t * ngx_resolver_t *
ngx_resolver_create(ngx_conf_t *cf, ngx_str_t *names, ngx_uint_t n) ngx_resolver_create(ngx_conf_t *cf, ngx_str_t *names, ngx_uint_t n)
{ {
@@ -246,6 +386,33 @@ ngx_resolver_create(ngx_conf_t *cf, ngx_str_t *names, ngx_uint_t n) @@ -246,6 +385,33 @@ ngx_resolver_create(ngx_conf_t *cf, ngx_str_t *names, ngx_uint_t n)
} }
#endif #endif

@ -134,3 +134,63 @@ successfully connected to openresty.org
--- no_error --- no_error
[error] [error]
[crit] [crit]
=== TEST 5: CRLF
--- config
resolver local=../html/resolv.conf ipv6=off;
resolver_timeout 5s;
location /t {
content_by_lua_block {
local sock = ngx.socket.tcp()
local ok, err = sock:connect("openresty.org", 80)
if not ok then
ngx.say("failed to connect to ", server, ": ", err)
return
end
ngx.say("successfully connected to openresty.org")
sock:close()
}
}
--- user_files eval
">>> resolv.conf
domain example.com\r\nnameserver 8.8.8.8\r\nnameserver 8.8.4.4"
--- request
GET /t
--- response_body
successfully connected to openresty.org
--- no_error
[error]
[crit]
=== TEST 6: CR only, with comments
--- config
resolver local=../html/resolv.conf ipv6=off;
resolver_timeout 5s;
location /t {
content_by_lua_block {
local sock = ngx.socket.tcp()
local ok, err = sock:connect("openresty.org", 80)
if not ok then
ngx.say("failed to connect to ", server, ": ", err)
return
end
ngx.say("successfully connected to openresty.org")
sock:close()
}
}
--- user_files eval
">>> resolv.conf
#domain example.com\rnameserver 8.8.8.8\rnameserver 8.8.4.4"
--- request
GET /t
--- response_body
successfully connected to openresty.org
--- no_error
[error]
[crit]

Loading…
Cancel
Save