Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nginx/nginx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2008-07-25 18:29:05 +0400
committerIgor Sysoev <igor@sysoev.ru>2008-07-25 18:29:05 +0400
commit96eaa05fd2523995f95d7410d5d8a48f76e5bca1 (patch)
treed7e9e08cedf59151e6d91d6e69a8857b408e7090 /src
parent6df67879a0a020262e514dace0c0349742800cd1 (diff)
fix utf-8 names in autoindex
Diffstat (limited to 'src')
-rw-r--r--src/core/ngx_string.c56
-rw-r--r--src/core/ngx_string.h2
-rw-r--r--src/http/modules/ngx_http_autoindex_module.c11
3 files changed, 37 insertions, 32 deletions
diff --git a/src/core/ngx_string.c b/src/core/ngx_string.c
index c9193152c..64ba703b7 100644
--- a/src/core/ngx_string.c
+++ b/src/core/ngx_string.c
@@ -955,7 +955,7 @@ ngx_decode_base64(ngx_str_t *dst, ngx_str_t *src)
* ngx_utf_decode() decodes two and more bytes UTF sequences only
* the return values:
* 0x80 - 0x10ffff valid character
- * 0x10ffff - 0xfffffffd invalid sequence
+ * 0x110000 - 0xfffffffd invalid sequence
* 0xfffffffe incomplete sequence
* 0xffffffff error
*/
@@ -1020,29 +1020,24 @@ ngx_utf_decode(u_char **p, size_t n)
size_t
ngx_utf_length(u_char *p, size_t n)
{
- u_char c;
- size_t len;
- ngx_uint_t i;
+ u_char c, *last;
+ size_t len;
- for (len = 0, i = 0; i < n; len++, i++) {
+ last = p + n;
- c = p[i];
+ for (len = 0; p < last; len++) {
+
+ c = *p;
if (c < 0x80) {
+ p++;
continue;
}
- if (c >= 0xc0) {
- for (c <<= 1; c & 0x80; c <<= 1) {
- i++;
- }
-
- continue;
+ if (ngx_utf_decode(&p, n) > 0x10ffff) {
+ /* invalid utf */
+ return n;
}
-
- /* invalid utf */
-
- return n;
}
return len;
@@ -1050,36 +1045,45 @@ ngx_utf_length(u_char *p, size_t n)
u_char *
-ngx_utf_cpystrn(u_char *dst, u_char *src, size_t n)
+ngx_utf_cpystrn(u_char *dst, u_char *src, size_t n, size_t len)
{
- u_char c;
+ u_char c, *next;
if (n == 0) {
return dst;
}
- for ( /* void */ ; --n; dst++, src++) {
+ while (--n) {
c = *src;
*dst = c;
if (c < 0x80) {
- if (*dst != '\0') {
+
+ if (c != '\0') {
+ dst++;
+ src++;
+ len--;
+
continue;
}
return dst;
}
- if (c >= 0xc0) {
- for (c <<= 1; c & 0x80; c <<= 1) {
- *++dst = *++src;
- }
+ next = src;
- continue;
+ if (ngx_utf_decode(&next, len) > 0x10ffff) {
+ /* invalid utf */
+ break;
}
- /* invalid utf */
+ len--;
+
+ while (src < next) {
+ *++dst = *++src;
+ len--;
+ }
}
*dst = '\0';
diff --git a/src/core/ngx_string.h b/src/core/ngx_string.h
index 3514e52f3..895925b6d 100644
--- a/src/core/ngx_string.h
+++ b/src/core/ngx_string.h
@@ -153,7 +153,7 @@ ngx_int_t ngx_decode_base64(ngx_str_t *dst, ngx_str_t *src);
uint32_t ngx_utf_decode(u_char **p, size_t n);
size_t ngx_utf_length(u_char *p, size_t n);
-u_char *ngx_utf_cpystrn(u_char *dst, u_char *src, size_t n);
+u_char *ngx_utf_cpystrn(u_char *dst, u_char *src, size_t n, size_t len);
#define NGX_ESCAPE_URI 0
diff --git a/src/http/modules/ngx_http_autoindex_module.c b/src/http/modules/ngx_http_autoindex_module.c
index b5b6ef7f3..64b29a8b3 100644
--- a/src/http/modules/ngx_http_autoindex_module.c
+++ b/src/http/modules/ngx_http_autoindex_module.c
@@ -135,7 +135,7 @@ ngx_http_autoindex_handler(ngx_http_request_t *r)
{
u_char *last, *filename, scale;
off_t length;
- size_t len, copy, allocated, root;
+ size_t len, utf_len, allocated, root;
ngx_tm_t tm;
ngx_err_t err;
ngx_buf_t *b;
@@ -412,15 +412,16 @@ ngx_http_autoindex_handler(ngx_http_request_t *r)
len = entry[i].utf_len;
- if (entry[i].name.len - len) {
+ if (entry[i].name.len != len) {
if (len > NGX_HTTP_AUTOINDEX_NAME_LEN) {
- copy = NGX_HTTP_AUTOINDEX_NAME_LEN - 3 + 1;
+ utf_len = NGX_HTTP_AUTOINDEX_NAME_LEN - 3 + 1;
} else {
- copy = NGX_HTTP_AUTOINDEX_NAME_LEN + 1;
+ utf_len = NGX_HTTP_AUTOINDEX_NAME_LEN + 1;
}
- b->last = ngx_utf_cpystrn(b->last, entry[i].name.data, copy);
+ b->last = ngx_utf_cpystrn(b->last, entry[i].name.data,
+ utf_len, entry[i].name.len + 1);
last = b->last;
} else {