]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
auth: Make sure auth cache doesn't break if any cache keys have TABs.
authorTimo Sirainen <tss@iki.fi>
Wed, 14 Mar 2012 12:59:24 +0000 (14:59 +0200)
committerTimo Sirainen <tss@iki.fi>
Wed, 14 Mar 2012 12:59:24 +0000 (14:59 +0200)
src/auth/auth-cache.c

index 5fea9f196823e50ad73a61ed592395616a83e8b1..1cf18f88c0bbf77e6ae0c1e8b3ff3e64c3739459 100644 (file)
@@ -207,6 +207,15 @@ void auth_cache_clear(struct auth_cache *cache)
        hash_table_clear(cache->hash, FALSE);
 }
 
+static const char *
+auth_cache_escape(const char *string,
+                 const struct auth_request *auth_request ATTR_UNUSED)
+{
+       /* cache key %variables are separated by tabs, make sure that there
+          are no tabs in the string */
+       return str_tabescape(string);
+}
+
 const char *
 auth_cache_lookup(struct auth_cache *cache, const struct auth_request *request,
                  const char *key, struct auth_cache_node **node_r,
@@ -225,7 +234,7 @@ auth_cache_lookup(struct auth_cache *cache, const struct auth_request *request,
        str = t_str_new(256);
        var_expand(str, t_strconcat(request->userdb_lookup ? "U" : "P",
                                    "%!/", key, NULL),
-                  auth_request_get_var_expand_table(request, NULL));
+                  auth_request_get_var_expand_table(request, auth_cache_escape));
 
        node = hash_table_lookup(cache->hash, str_c(str));
        if (node == NULL) {
@@ -281,7 +290,7 @@ void auth_cache_insert(struct auth_cache *cache, struct auth_request *request,
        str = t_str_new(256);
        var_expand(str, t_strconcat(request->userdb_lookup ? "U" : "P",
                                    "%!/", key, NULL),
-                  auth_request_get_var_expand_table(request, NULL));
+                  auth_request_get_var_expand_table(request, auth_cache_escape));
 
        request->user = current_username;
 
@@ -330,7 +339,7 @@ void auth_cache_remove(struct auth_cache *cache,
 
        str = t_str_new(256);
        var_expand(str, key,
-                  auth_request_get_var_expand_table(request, NULL));
+                  auth_request_get_var_expand_table(request, auth_cache_escape));
 
        node = hash_table_lookup(cache->hash, str_c(str));
        if (node == NULL)