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.3.0.rc1~1102 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c5ed1bc7a17d98e1ee5f8987d839522b83888925;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 6be6c92a45..3ccfee213e 100644 --- a/src/lib-mail/mail-user-hash.c +++ b/src/lib-mail/mail-user-hash.c @@ -41,6 +41,12 @@ bool 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; + } *hash_r = hash; *error_r = t_strdup(error_dup); i_free(error_dup); diff --git a/src/lib-mail/mail-user-hash.h b/src/lib-mail/mail-user-hash.h index 5362389a69..e3a9e593ee 100644 --- a/src/lib-mail/mail-user-hash.h +++ b/src/lib-mail/mail-user-hash.h @@ -2,7 +2,8 @@ #define MAIL_USER_HASH /* Get a hash for username, based on given format. The format can use - %n, %d and %u variables. Returns TRUE if ok, FALSE if format is invalid. */ + %n, %d and %u variables. The returned hash is never 0. + Returns TRUE if ok, FALSE if format is invalid. */ bool mail_user_hash(const char *username, const char *format, unsigned int *hash_r, const char **error_r);