summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2007-03-29 15:20:52 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2007-03-29 15:20:52 +0000
commit1b914275d95061187a3f6faebe302599343ad081 (patch)
tree22b750987e7f013b9e8024141fa170c465f3a6a6
parenta27de5628c1680555523008fd4db23f69ab7b05b (diff)
Fix a cust & pasto
Correctly compute amount of base64 padding in checklist mode
-rw-r--r--bin/md5/md5.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/bin/md5/md5.c b/bin/md5/md5.c
index c6dc42468d0..cf3f2e47655 100644
--- a/bin/md5/md5.c
+++ b/bin/md5/md5.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: md5.c,v 1.43 2007/03/29 13:02:17 millert Exp $ */
+/* $OpenBSD: md5.c,v 1.44 2007/03/29 15:20:51 millert Exp $ */
/*
* Copyright (c) 2001,2003,2005-2006 Todd C. Miller <Todd.Miller@courtesan.com>
@@ -108,7 +108,7 @@ struct hash_function {
(char *(*)(void *, char *))SYSVSUM_End
}, {
"MD4",
- MD5_DIGEST_LENGTH,
+ MD4_DIGEST_LENGTH,
&style_hash,
0,
NULL,
@@ -587,9 +587,16 @@ digest_filelist(const char *file, struct hash_function *defhash)
*/
len = strlen(checksum);
if (len != hf->digestlen * 2) {
- size_t len2 = (8 * hf->digestlen + 5) / 6;
- if (len != len2 &&
- (len != len2 + 1 || checksum[len - 1] != '='))
+ size_t len2;
+
+ if (checksum[len - 1] == '=') {
+ /* use padding */
+ len2 = 4 * ((hf->digestlen + 2) / 3);
+ } else {
+ /* no padding */
+ len2 = (4 * hf->digestlen + 2) / 3;
+ }
+ if (len != len2)
continue;
base64 = 1;
}
@@ -636,10 +643,9 @@ digest_filelist(const char *file, struct hash_function *defhash)
close(fd);
digest_end(hf, &context, digest, sizeof(digest), base64);
- if (base64) {
- len = strlen(digest) - 1; /* remove padding '=' */
+ if (base64)
error = strncmp(checksum, digest, len);
- } else
+ else
error = strcasecmp(checksum, digest);
if (error == 0) {
if (qflag == 0)