]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-mail: Make sure mail_user_hash() won't return 0 as the hash.
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 19 Jul 2017 13:49:18 +0000 (16:49 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 12 Sep 2017 10:54:40 +0000 (13:54 +0300)
It doesn't seem to actually happen, but this makes sure of it.

src/lib-mail/mail-user-hash.c
src/lib-mail/mail-user-hash.h

index 3dc1ff8bbe416fec148f67246eae125619f839ba..d8f1f50d444f72b75ef7e5d829d9b2648058caa8 100644 (file)
@@ -42,6 +42,12 @@ unsigned int mail_user_hash(const char *username, const char *format)
        } T_END;
        for (i = 0; i < sizeof(hash); i++)
                hash = (hash << CHAR_BIT) | md5[i];
+       if (hash == 0) {
+               /* Make sure we don't return the hash as 0, since it's often
+                  treated in a special way that won't work well. For example
+                  trying to insert it into a hash table will assert-crash. */
+               hash = 1;
+       }
        return hash;
 }
 
index 3287dfcd0523b027528fbf3332c99434200860fe..76fd0ab1ac12cd5bed269f33dc8f454aae60daf3 100644 (file)
@@ -2,7 +2,7 @@
 #define MAIL_USER_HASH
 
 /* Return a hash for username, based on given format. The format can use
-   %n, %d and %u variables. */
+   %n, %d and %u variables. The returned hash is never 0. */
 unsigned int mail_user_hash(const char *username, const char *format);
 
 #endif