From 9d799d1171276f8a8bdfa6d5a07b8ecd75ab02b4 Mon Sep 17 00:00:00 2001 From: millert <> Date: Thu, 16 Sep 2004 15:12:09 +0000 Subject: [PATCH] Fix MD5FileChunk() when passed a 0 length; makes MD5File() work again. From Peter Galbavy. --- src/lib/libc/hash/helper.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/lib/libc/hash/helper.c b/src/lib/libc/hash/helper.c index 016a31ec..bf3a6c24 100644 --- a/src/lib/libc/hash/helper.c +++ b/src/lib/libc/hash/helper.c @@ -1,4 +1,4 @@ -/* $OpenBSD: helper.c,v 1.6 2004/06/22 01:57:29 jfb Exp $ */ +/* $OpenBSD: helper.c,v 1.7 2004/09/16 15:12:09 millert Exp $ */ /* * ---------------------------------------------------------------------------- @@ -10,10 +10,11 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$OpenBSD: helper.c,v 1.6 2004/06/22 01:57:29 jfb Exp $"; +static const char rcsid[] = "$OpenBSD: helper.c,v 1.7 2004/09/16 15:12:09 millert Exp $"; #endif /* LIBC_SCCS and not lint */ #include +#include #include #include @@ -48,6 +49,7 @@ HASHEnd(HASH_CTX *ctx, char *buf) char * HASHFileChunk(const char *filename, char *buf, off_t off, off_t len) { + struct stat sb; u_char buffer[BUFSIZ]; HASH_CTX ctx; int fd, save_errno; @@ -57,6 +59,13 @@ HASHFileChunk(const char *filename, char *buf, off_t off, off_t len) if ((fd = open(filename, O_RDONLY)) < 0) return (NULL); + if (len == 0) { + if (fstat(fd, &sb) == -1) { + close(fd); + return (NULL); + } + len = sb.st_size; + } if (off > 0 && lseek(fd, off, SEEK_SET) < 0) return (NULL);