[dovecot-cvs] dovecot/src/auth auth-cache.c,1.5,1.6

cras at dovecot.org cras at dovecot.org
Wed Dec 15 20:06:49 EET 2004


Update of /var/lib/cvs/dovecot/src/auth
In directory talvi:/tmp/cvs-serv22762

Modified Files:
	auth-cache.c 
Log Message:
When building cache key, use each %key only once, more wastes only memory.
This was mostly needed for more complex SQL queries where same key could be
used multiple times.



Index: auth-cache.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/auth-cache.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- auth-cache.c	6 Nov 2004 20:55:31 -0000	1.5
+++ auth-cache.c	15 Dec 2004 18:06:47 -0000	1.6
@@ -30,16 +30,22 @@
 char *auth_cache_parse_key(const char *query)
 {
 	string_t *str;
+	char key_seen[256];
+
+	memset(key_seen, 0, sizeof(key_seen));
 
 	str = str_new(default_pool, 32);
 	for (; *query != '\0'; query++) {
 		if (*query == '%' && query[1] != '\0') {
 			query++;
-			if (*query != '%') {
+			if (*query != '%' && !key_seen[(uint8_t)*query]) {
 				if (str_len(str) != 0)
 					str_append_c(str, '\t');
 				str_append_c(str, '%');
 				str_append_c(str, *query);
+
+				/* @UNSAFE */
+                                key_seen[(uint8_t)*query] = 1;
 			}
 		}
 	}



More information about the dovecot-cvs mailing list