From cc90bdfd083036c9646f35ad6fa375af4ff92526 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Tue, 23 Jul 2002 13:11:53 -0400 Subject: [PATCH] dirhash.c (ext2fs_dirhash): Fix bug which caused MD4 calculations for names > 32 characters to be completely bogus. Changed MD4 calculation to match what is currently being used in the CVS gkernel tree. --- lib/ext2fs/ChangeLog | 7 +++++++ lib/ext2fs/dirhash.c | 9 +++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/ext2fs/ChangeLog b/lib/ext2fs/ChangeLog index 4bbbca2..c946de5 100644 --- a/lib/ext2fs/ChangeLog +++ b/lib/ext2fs/ChangeLog @@ -1,3 +1,10 @@ +2002-07-23 Theodore Ts'o + + * dirhash.c (ext2fs_dirhash): Fix bug which caused MD4 + calculations for names > 32 characters to be completely + bogus. Changed MD4 calculation to match what is currently + being used in the CVS gkernel tree. + 2002-07-19 Theodore Ts'o * ext2_fs.h: Add s_hash_seed and s_def_hash_version to the diff --git a/lib/ext2fs/dirhash.c b/lib/ext2fs/dirhash.c index 1d21fe5..d3e0e75 100644 --- a/lib/ext2fs/dirhash.c +++ b/lib/ext2fs/dirhash.c @@ -75,7 +75,7 @@ static __u32 halfMD4Transform (__u32 buf[4], __u32 const in[]) buf[2] += c; buf[3] += d; - return (buf[1] << 1); /* "most hashed" word */ + return ((buf[1] + b) & ~1); /* "most hashed" word */ /* Alternative: return sum of all words? */ } @@ -121,7 +121,7 @@ errcode_t ext2fs_dirhash(int version, const char *name, int len, { __u32 hash; __u32 minor_hash = 0; - char *p; + const char *p; int i; /* Check to see if the seed is all zero's */ @@ -144,10 +144,11 @@ errcode_t ext2fs_dirhash(int version, const char *name, int len, buf[2] = 0x98badcfe; buf[3] = 0x10325476; } else - memcpy(buf, in, sizeof(buf)); + memcpy(buf, seed, sizeof(buf)); + p = name; while (len) { if (len < 32) { - memcpy(in, name, len); + memcpy(in, p, len); memset(in+len, 0, 32-len); hash = halfMD4Transform(buf, (__u32 *) in); break; -- 1.8.3.1