# HG changeset patch # User Igor Sysoev # Date 1165414662 0 # Node ID 6356b34cf0276b66759431b29a424e50b9d9cf45 # Parent a9a7e4b1a72b0e9852baebc0ac95eeecb82d8e28 fix when last htpasswd line has no CR or LF diff --git a/src/http/modules/ngx_http_auth_basic_module.c b/src/http/modules/ngx_http_auth_basic_module.c --- a/src/http/modules/ngx_http_auth_basic_module.c +++ b/src/http/modules/ngx_http_auth_basic_module.c @@ -154,6 +154,8 @@ ngx_http_auth_basic_handler(ngx_http_req offset = 0; for ( ;; ) { + i = left; + n = ngx_read_file(&file, buf + left, NGX_HTTP_AUTH_BUF_SIZE - left, offset); @@ -228,6 +230,18 @@ ngx_http_auth_basic_handler(ngx_http_req ngx_http_auth_basic_close(&file); + if (state == sw_passwd) { + pwd.len = i - passwd; + pwd.data = ngx_palloc(r->pool, pwd.len + 1); + if (pwd.data == NULL) { + return NGX_HTTP_INTERNAL_SERVER_ERROR; + } + + ngx_cpystrn(pwd.data, &buf[passwd], pwd.len + 1); + + return ngx_http_auth_basic_crypt_handler(r, NULL, &pwd, &alcf->realm); + } + return ngx_http_auth_basic_set_realm(r, &alcf->realm); }