summaryrefslogtreecommitdiff
path: root/lib/libc/hash/helper.c
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2004-09-16 15:12:10 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2004-09-16 15:12:10 +0000
commit7a3af50607a1ab6f9cbd52b9d0e81f24a47ba672 (patch)
tree2bfbc5bee1a014e99ee93622b057030023672fe3 /lib/libc/hash/helper.c
parent5f92e01b3daa4f01bde95c45beca9dfdb9e2cc9f (diff)
Fix MD5FileChunk() when passed a 0 length; makes MD5File() work again.
From Peter Galbavy.
Diffstat (limited to 'lib/libc/hash/helper.c')
-rw-r--r--lib/libc/hash/helper.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/lib/libc/hash/helper.c b/lib/libc/hash/helper.c
index 016a31ecd4e..bf3a6c243c5 100644
--- a/lib/libc/hash/helper.c
+++ b/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 <sys/param.h>
+#include <sys/stat.h>
#include <errno.h>
#include <fcntl.h>
@@ -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);