subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stef...@apache.org
Subject svn commit: r1462907 - /subversion/trunk/subversion/libsvn_fs_fs/caching.c
Date Sun, 31 Mar 2013 10:03:01 GMT
Author: stefan2
Date: Sun Mar 31 10:03:00 2013
New Revision: 1462907

URL: http://svn.apache.org/r1462907
Log:
When constructing the key prefix that we use for key space separation
in FSFS caches,  make sure that the ":" delimiter is not found in any
of the key parts.  Otherwise, we might be able to construct the same
prefix using a different combination of elements.

Normalizing those parts that potentially need it must not limit their
value space, however, as this would again allow for different element
values to result in the same key prefix.

* subversion/libsvn_fs_fs/caching.c
  (normalize_namespace): new utility function
  (read_config,
   svn_fs_fs__initialize_caches): normalize elements of the key prefix

Modified:
    subversion/trunk/subversion/libsvn_fs_fs/caching.c

Modified: subversion/trunk/subversion/libsvn_fs_fs/caching.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_fs_fs/caching.c?rev=1462907&r1=1462906&r2=1462907&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_fs_fs/caching.c (original)
+++ subversion/trunk/subversion/libsvn_fs_fs/caching.c Sun Mar 31 10:03:00 2013
@@ -38,6 +38,33 @@
 #include "private/svn_debug.h"
 #include "private/svn_subr_private.h"
 
+/* Take the ORIGINAL string and replace all occurrences of ":" without
+ * limiting the key space.  Allocate the result in POOL.
+ */
+static const char *
+normalize_key_part(const char *original,
+                   apr_pool_t *pool)
+{
+  apr_size_t i;
+  apr_size_t len = strlen(original);
+  svn_stringbuf_t *normalized = svn_stringbuf_create_ensure(len, pool);
+
+  for (i = 0; i < len; ++i)
+    {
+      char c = original[i];
+      switch (c)
+        {
+        case ':': svn_stringbuf_appendbytes(normalized, "%_", 2);
+                  break;
+        case '%': svn_stringbuf_appendbytes(normalized, "%%", 2);
+                  break;
+        default : svn_stringbuf_appendbyte(normalized, c);
+        }
+    }
+
+  return normalized->data;
+}
+
 /* Return a memcache in *MEMCACHE_P for FS if it's configured to use
    memcached, or NULL otherwise.  Also, sets *FAIL_STOP to a boolean
    indicating whether cache errors should be returned to the caller or
@@ -69,12 +96,16 @@ read_config(svn_memcache_t **memcache_p,
    * share / compete for the same cache memory but keys will not match
    * across namespaces and, thus, cached data will not be shared between
    * namespaces.
+   *
+   * Since the namespace will be concatenated with other elements to form
+   * the complete key prefix, we must make sure that the resulting string
+   * is unique and cannot be created by any other combination of elements.
    */
   *cache_namespace
-    = apr_pstrdup(fs->pool,
-                  svn_hash__get_cstring(fs->config,
-                                        SVN_FS_CONFIG_FSFS_CACHE_NS,
-                                        ""));
+    = normalize_key_part(svn_hash__get_cstring(fs->config,
+                                               SVN_FS_CONFIG_FSFS_CACHE_NS,
+                                               ""),
+                         pool);
 
   /* don't cache text deltas by default.
    * Once we reconstructed the fulltexts from the deltas,
@@ -313,7 +344,8 @@ svn_fs_fs__initialize_caches(svn_fs_t *f
   fs_fs_data_t *ffd = fs->fsap_data;
   const char *prefix = apr_pstrcat(pool,
                                    "fsfs:", fs->uuid,
-                                   "/", fs->path, ":",
+                                   "/", normalize_key_part(fs->path, pool),
+                                   ":",
                                    (char *)NULL);
   svn_memcache_t *memcache;
   svn_membuffer_t *membuffer;



Mime
View raw message