]> git.kaiwu.me - nginx.git/commitdiff
ngx_path_separator()
authorIgor Sysoev <igor@sysoev.ru>
Thu, 23 Apr 2009 16:38:59 +0000 (16:38 +0000)
committerIgor Sysoev <igor@sysoev.ru>
Thu, 23 Apr 2009 16:38:59 +0000 (16:38 +0000)
src/http/ngx_http_parse.c
src/http/ngx_http_request.c
src/os/unix/ngx_files.h
src/os/win32/ngx_files.h

index 11e62e6ac42d946b8e842653f4bafa9d010fb0cb..4aa1be8edbe0639187eea9ab6504b73b3df58835 100644 (file)
@@ -1337,12 +1337,7 @@ ngx_http_parse_unsafe_uri(ngx_http_request_t *r, ngx_str_t *uri,
         goto unsafe;
     }
 
-    if (p[0] == '.' && len == 3 && p[1] == '.' && (p[2] == '/'
-#if (NGX_WIN32)
-                                                   || p[2] == '\\'
-#endif
-        ))
-    {
+    if (p[0] == '.' && len == 3 && p[1] == '.' && (ngx_path_separator(p[2]))) {
         goto unsafe;
     }
 
@@ -1367,30 +1362,22 @@ ngx_http_parse_unsafe_uri(ngx_http_request_t *r, ngx_str_t *uri,
             continue;
         }
 
-        if ((ch == '/'
-#if (NGX_WIN32)
-             || ch == '\\'
-#endif
-            ) && len > 2)
-        {
+        if (ngx_path_separator(ch) && len > 2) {
+
             /* detect "/../" */
 
-            if (p[0] == '.' && p[1] == '.' && p[2] == '/') {
+            if (p[0] == '.' && p[1] == '.' && ngx_path_separator(p[2])) {
                 goto unsafe;
             }
 
 #if (NGX_WIN32)
 
-            if (p[2] == '\\') {
-                goto unsafe;
-            }
-
             if (len > 3) {
 
                 /* detect "/.../" */
 
                 if (p[0] == '.' && p[1] == '.' && p[2] == '.'
-                    && (p[3] == '/' || p[3] == '\\'))
+                    && ngx_path_separator(p[3]))
                 {
                     goto unsafe;
                 }
index 31ab640e24ccb26ef387b2d7188479b8aefa3450..d06c6dd3fb9c957f824a7665fe25ff77a19b4e40 100644 (file)
@@ -1587,15 +1587,9 @@ ngx_http_validate_host(u_char *host, size_t len)
             continue;
         }
 
-        if (ch == '/' || ch == '\0') {
+        if (ngx_path_separator(ch) || ch == '\0') {
             return -1;
         }
-
-#if (NGX_WIN32)
-        if (ch == '\\') {
-            return -1;
-        }
-#endif
     }
 
     if (dot) {
index 63d080b5c2e11fa0783a5d30f4fedbf775727cf6..7d83b04e7a67f3ecdfee20e226c6c5b77b4ee1cd 100644 (file)
@@ -160,6 +160,8 @@ ngx_int_t ngx_set_file_time(u_char *name, ngx_fd_t fd, time_t s);
 #define ngx_realpath_n           "realpath()"
 #define ngx_getcwd(buf, size)    (getcwd(buf, size) != NULL)
 #define ngx_getcwd_n             "getcwd()"
+#define ngx_path_separator(c)    ((c) == '/')
+
 #define NGX_MAX_PATH             PATH_MAX
 
 #define NGX_DIR_MASK_LEN         0
index f3561d9b367153133f196b73b68785e6c691e563..1e2c630aecf5132a72ed35573e61c828ea4865e3 100644 (file)
@@ -154,6 +154,8 @@ char *ngx_realpath(u_char *path, u_char *resolved);
 #define ngx_realpath_n              ""
 #define ngx_getcwd(buf, size)       GetCurrentDirectory(size, buf)
 #define ngx_getcwd_n                "GetCurrentDirectory()"
+#define ngx_path_separator(c)       ((c) == '/' || (c) == '\\')
+
 #define NGX_MAX_PATH                MAX_PATH