You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by yl...@apache.org on 2024/06/26 14:56:47 UTC

svn commit: r1918668 - in /httpd/httpd/branches/2.4.x: ./ include/ap_mmn.h include/httpd.h modules/mappers/mod_rewrite.c server/util.c

Author: ylavic
Date: Wed Jun 26 14:56:47 2024
New Revision: 1918668

URL: http://svn.apache.org/viewvc?rev=1918668&view=rev
Log:
factor out IS_SLASH, perdir fix

in per-dir, the filename will be internally redirected, so / is OK too.


don't add / to / in the non-perdir


match AP_IS_SLASH macro

followup to 1918651


Merges r1918651, r1918652, r1918663 from trunk
Reviewed by: covener, ylavic, rpluem
GH: close #458

Modified:
    httpd/httpd/branches/2.4.x/   (props changed)
    httpd/httpd/branches/2.4.x/include/ap_mmn.h
    httpd/httpd/branches/2.4.x/include/httpd.h
    httpd/httpd/branches/2.4.x/modules/mappers/mod_rewrite.c
    httpd/httpd/branches/2.4.x/server/util.c

Propchange: httpd/httpd/branches/2.4.x/
------------------------------------------------------------------------------
  Merged /httpd/httpd/trunk:r1918651-1918652,1918663

Modified: httpd/httpd/branches/2.4.x/include/ap_mmn.h
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/include/ap_mmn.h?rev=1918668&r1=1918667&r2=1918668&view=diff
==============================================================================
--- httpd/httpd/branches/2.4.x/include/ap_mmn.h (original)
+++ httpd/httpd/branches/2.4.x/include/ap_mmn.h Wed Jun 26 14:56:47 2024
@@ -602,6 +602,7 @@
  * 20120211.132 (2.4.60-dev) Add ap_set_content_type_ex(), ap_filepath_merge(),
  *                           and AP_REQUEST_TRUSTED_CT BNOTE.
  * 20120211.133 (2.4.60-dev) Add ap_proxy_fixup_uds_filename()
+ * 20120211.134 (2.4.60-dev) AP_SLASHES and AP_IS_SLASH
  */
 
 #define MODULE_MAGIC_COOKIE 0x41503234UL /* "AP24" */
@@ -609,7 +610,7 @@
 #ifndef MODULE_MAGIC_NUMBER_MAJOR
 #define MODULE_MAGIC_NUMBER_MAJOR 20120211
 #endif
-#define MODULE_MAGIC_NUMBER_MINOR 133                 /* 0...n */
+#define MODULE_MAGIC_NUMBER_MINOR 134                 /* 0...n */
 
 /**
  * Determine if the server's current MODULE_MAGIC_NUMBER is at least a

Modified: httpd/httpd/branches/2.4.x/include/httpd.h
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/include/httpd.h?rev=1918668&r1=1918667&r2=1918668&view=diff
==============================================================================
--- httpd/httpd/branches/2.4.x/include/httpd.h (original)
+++ httpd/httpd/branches/2.4.x/include/httpd.h Wed Jun 26 14:56:47 2024
@@ -2688,6 +2688,17 @@ AP_DECLARE(apr_status_t) ap_filepath_mer
 #define apr_filepath_merge  ap_filepath_merge
 #endif
 
+/* Win32/NetWare/OS2 need to check for both forward and back slashes
+ * in ap_normalize_path() and ap_escape_url().
+ */
+#ifdef CASE_BLIND_FILESYSTEM
+#define AP_IS_SLASH(s) ((s == '/') || (s == '\\'))
+#define AP_SLASHES "/\\"
+#else
+#define AP_IS_SLASH(s) (s == '/')
+#define AP_SLASHES "/"
+#endif
+
 #ifdef __cplusplus
 }
 #endif

Modified: httpd/httpd/branches/2.4.x/modules/mappers/mod_rewrite.c
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/modules/mappers/mod_rewrite.c?rev=1918668&r1=1918667&r2=1918668&view=diff
==============================================================================
--- httpd/httpd/branches/2.4.x/modules/mappers/mod_rewrite.c (original)
+++ httpd/httpd/branches/2.4.x/modules/mappers/mod_rewrite.c Wed Jun 26 14:56:47 2024
@@ -655,14 +655,11 @@ static unsigned is_absolute_uri(char *ur
 
 static int is_absolute_path(const char *path)
 {
-#ifndef WIN32
+#ifndef CASE_BLIND_FILESYSTEM
     return (path[0] == '/');
 #else
-#define IS_SLASH(c) ((c) == '/' || (c) == '\\')
-    /* "//", "\\", "x:/" and "x:\" are absolute paths on Windows */
-    return ((IS_SLASH(path[0]) && path[1] == path[0])
-            || (apr_isalpha(path[0]) && path[1] == ':' && IS_SLASH(path[2])));
-#undef IS_SLASH
+    return ((AP_IS_SLASH(path[0]) && path[1] == path[0])
+            || (apr_isalpha(path[0]) && path[1] == ':' && AP_IS_SLASH(path[2])));
 #endif
 }
 
@@ -4366,11 +4363,11 @@ static rule_return_type apply_rewrite_ru
      */
     if (!is_proxyreq
         && !is_absolute_path(newuri)
+        && !AP_IS_SLASH(*newuri)
         && !is_absolute_uri(newuri, NULL)) {
         if (ctx->perdir) {
             rewritelog((r, 3, ctx->perdir, "add per-dir prefix: %s -> %s%s",
                        newuri, ctx->perdir, newuri));
-
             newuri = apr_pstrcat(r->pool, ctx->perdir, newuri, NULL);
         }
         else if (!(p->flags & (RULEFLAG_PROXY | RULEFLAG_FORCEREDIRECT))) {

Modified: httpd/httpd/branches/2.4.x/server/util.c
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/server/util.c?rev=1918668&r1=1918667&r2=1918668&view=diff
==============================================================================
--- httpd/httpd/branches/2.4.x/server/util.c (original)
+++ httpd/httpd/branches/2.4.x/server/util.c Wed Jun 26 14:56:47 2024
@@ -75,17 +75,6 @@
  */
 #include "test_char.h"
 
-/* Win32/NetWare/OS2 need to check for both forward and back slashes
- * in ap_normalize_path() and ap_escape_url().
- */
-#ifdef CASE_BLIND_FILESYSTEM
-#define IS_SLASH(s) ((s == '/') || (s == '\\'))
-#define SLASHES "/\\"
-#else
-#define IS_SLASH(s) (s == '/')
-#define SLASHES "/"
-#endif
-
 /* we know core's module_index is 0 */
 #undef APLOG_MODULE_INDEX
 #define APLOG_MODULE_INDEX AP_CORE_MODULE_INDEX
@@ -492,7 +481,7 @@ AP_DECLARE(apr_status_t) ap_pregsub_ex(a
 /* Forward declare */
 static char x2c(const char *what);
 
-#define IS_SLASH_OR_NUL(s) (s == '\0' || IS_SLASH(s))
+#define IS_SLASH_OR_NUL(s) (s == '\0' || AP_IS_SLASH(s))
 
 /*
  * Inspired by mod_jk's jk_servlet_normalize().
@@ -504,7 +493,7 @@ AP_DECLARE(int) ap_normalize_path(char *
     int decode_unreserved = (flags & AP_NORMALIZE_DECODE_UNRESERVED) != 0;
     int merge_slashes = (flags & AP_NORMALIZE_MERGE_SLASHES) != 0;
 
-    if (!IS_SLASH(path[0])) {
+    if (!AP_IS_SLASH(path[0])) {
         /* Besides "OPTIONS *", a request-target should start with '/'
          * per RFC 7230 section 5.3, so anything else is invalid.
          */
@@ -545,12 +534,12 @@ AP_DECLARE(int) ap_normalize_path(char *
             }
         }
 
-        if (w == 0 || IS_SLASH(path[w - 1])) {
+        if (w == 0 || AP_IS_SLASH(path[w - 1])) {
             /* Collapse ///// sequences to / */
-            if (merge_slashes && IS_SLASH(path[l])) {
+            if (merge_slashes && AP_IS_SLASH(path[l])) {
                 do {
                     l++;
-                } while (IS_SLASH(path[l]));
+                } while (AP_IS_SLASH(path[l]));
                 continue;
             }
 
@@ -579,7 +568,7 @@ AP_DECLARE(int) ap_normalize_path(char *
                     if (w > 1) {
                         do {
                             w--;
-                        } while (w && !IS_SLASH(path[w - 1]));
+                        } while (w && !AP_IS_SLASH(path[w - 1]));
                     }
                     else {
                         /* Already at root, ignore and return a failure
@@ -1915,7 +1904,7 @@ static int unescape_url(char *url, const
                 char decoded;
                 decoded = x2c(y + 1);
                 if ((decoded == '\0')
-                    || (forbid_slashes && IS_SLASH(decoded))
+                    || (forbid_slashes && AP_IS_SLASH(decoded))
                     || (forbid && ap_strchr_c(forbid, decoded))) {
                     badpath = 1;
                     *x = decoded;
@@ -1923,7 +1912,7 @@ static int unescape_url(char *url, const
                 }
                 else if ((keep_unreserved && TEST_CHAR(decoded,
                                                        T_URI_UNRESERVED))
-                         || (keep_slashes && IS_SLASH(decoded))
+                         || (keep_slashes && AP_IS_SLASH(decoded))
                          || (reserved && ap_strchr_c(reserved, decoded))) {
                     *x++ = *y++;
                     *x++ = *y++;
@@ -1950,7 +1939,7 @@ static int unescape_url(char *url, const
 AP_DECLARE(int) ap_unescape_url(char *url)
 {
     /* Traditional */
-    return unescape_url(url, SLASHES, NULL, 0);
+    return unescape_url(url, AP_SLASHES, NULL, 0);
 }
 AP_DECLARE(int) ap_unescape_url_keep2f(char *url, int decode_slashes)
 {
@@ -1960,7 +1949,7 @@ AP_DECLARE(int) ap_unescape_url_keep2f(c
         return unescape_url(url, NULL, NULL, 0);
     } else {
         /* reserve (do not decode) encoded slashes */
-        return unescape_url(url, NULL, SLASHES, 0);
+        return unescape_url(url, NULL, AP_SLASHES, 0);
     }
 }
 AP_DECLARE(int) ap_unescape_url_ex(char *url, unsigned int flags)