From: Timo Sirainen Date: Wed, 19 Jul 2017 13:49:18 +0000 (+0300) Subject: lib-mail: Make sure mail_user_hash() won't return 0 as the hash. X-Git-Tag: 2.2.33.rc1~99 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b1f56afa6d111233218f5e21958d8be290aa2a6e;p=thirdparty%2Fdovecot%2Fcore.git lib-mail: Make sure mail_user_hash() won't return 0 as the hash. It doesn't seem to actually happen, but this makes sure of it. --- diff --git a/src/lib-mail/mail-user-hash.c b/src/lib-mail/mail-user-hash.c index 3dc1ff8bbe..d8f1f50d44 100644 --- a/src/lib-mail/mail-user-hash.c +++ b/src/lib-mail/mail-user-hash.c @@ -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; } diff --git a/src/lib-mail/mail-user-hash.h b/src/lib-mail/mail-user-hash.h index 3287dfcd05..76fd0ab1ac 100644 --- a/src/lib-mail/mail-user-hash.h +++ b/src/lib-mail/mail-user-hash.h @@ -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