The hashing routines (MD5File() and co.) can do dynamic allocation, so

take advantage of that instead of an ugly hard-coded MAXHASHLEN limit
that needs updating.

I think this was suggested by cube@ years ago.
This commit is contained in:
elad 2007-02-04 08:03:18 +00:00
parent 5a003ebca0
commit 3044852cc5
3 changed files with 31 additions and 22 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: compare.c,v 1.50 2006/12/14 20:21:47 he Exp $ */
/* $NetBSD: compare.c,v 1.51 2007/02/04 08:03:18 elad Exp $ */
/*-
* Copyright (c) 1989, 1993
@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)compare.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: compare.c,v 1.50 2006/12/14 20:21:47 he Exp $");
__RCSID("$NetBSD: compare.c,v 1.51 2007/02/04 08:03:18 elad Exp $");
#endif
#endif /* not lint */
@ -132,7 +132,7 @@ compare(NODE *s, FTSENT *p)
int fd, label;
const char *cp, *tab;
#if !defined(NO_MD5) || !defined(NO_RMD160) || !defined(NO_SHA1) || !defined(NO_SHA2)
char digestbuf[MAXHASHLEN + 1];
char *digestbuf;
#endif
tab = NULL;
@ -392,7 +392,7 @@ typeerr: LABEL;
}
#ifndef NO_MD5
if (s->flags & F_MD5) {
if (MD5File(p->fts_accpath, digestbuf) == NULL) {
if ((digestbuf = MD5File(p->fts_accpath, NULL)) == NULL) {
LABEL;
printf("%smd5: %s: %s\n",
tab, p->fts_accpath, strerror(errno));
@ -404,12 +404,13 @@ typeerr: LABEL;
tab, s->md5digest, digestbuf);
}
tab = "\t";
free(digestbuf);
}
}
#endif /* ! NO_MD5 */
#ifndef NO_RMD160
if (s->flags & F_RMD160) {
if (RMD160File(p->fts_accpath, digestbuf) == NULL) {
if ((digestbuf = RMD160File(p->fts_accpath, NULL)) == NULL) {
LABEL;
printf("%srmd160: %s: %s\n",
tab, p->fts_accpath, strerror(errno));
@ -421,12 +422,13 @@ typeerr: LABEL;
tab, s->rmd160digest, digestbuf);
}
tab = "\t";
free(digestbuf);
}
}
#endif /* ! NO_RMD160 */
#ifndef NO_SHA1
if (s->flags & F_SHA1) {
if (SHA1File(p->fts_accpath, digestbuf) == NULL) {
if ((digestbuf = SHA1File(p->fts_accpath, NULL)) == NULL) {
LABEL;
printf("%ssha1: %s: %s\n",
tab, p->fts_accpath, strerror(errno));
@ -438,12 +440,13 @@ typeerr: LABEL;
tab, s->sha1digest, digestbuf);
}
tab = "\t";
free(digestbuf);
}
}
#endif /* ! NO_SHA1 */
#ifndef NO_SHA2
if (s->flags & F_SHA256) {
if (SHA256_File(p->fts_accpath, digestbuf) == NULL) {
if ((digestbuf = SHA256_File(p->fts_accpath, NULL)) == NULL) {
LABEL;
printf("%ssha256: %s: %s\n",
tab, p->fts_accpath, strerror(errno));
@ -455,10 +458,11 @@ typeerr: LABEL;
tab, s->sha256digest, digestbuf);
}
tab = "\t";
free(digestbuf);
}
}
if (s->flags & F_SHA384) {
if (SHA384_File(p->fts_accpath, digestbuf) == NULL) {
if ((digestbuf = SHA384_File(p->fts_accpath, NULL)) == NULL) {
LABEL;
printf("%ssha384: %s: %s\n",
tab, p->fts_accpath, strerror(errno));
@ -470,10 +474,11 @@ typeerr: LABEL;
tab, s->sha384digest, digestbuf);
}
tab = "\t";
free(digestbuf);
}
}
if (s->flags & F_SHA512) {
if (SHA512_File(p->fts_accpath, digestbuf) == NULL) {
if ((digestbuf = SHA512_File(p->fts_accpath, NULL)) == NULL) {
LABEL;
printf("%ssha512: %s: %s\n",
tab, p->fts_accpath, strerror(errno));
@ -485,6 +490,7 @@ typeerr: LABEL;
tab, s->sha512digest, digestbuf);
}
tab = "\t";
free(digestbuf);
}
}
#endif /* ! NO_SHA2 */

View File

@ -1,4 +1,4 @@
/* $NetBSD: create.c,v 1.50 2006/10/30 20:22:54 christos Exp $ */
/* $NetBSD: create.c,v 1.51 2007/02/04 08:03:18 elad Exp $ */
/*-
* Copyright (c) 1989, 1993
@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)create.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: create.c,v 1.50 2006/10/30 20:22:54 christos Exp $");
__RCSID("$NetBSD: create.c,v 1.51 2007/02/04 08:03:18 elad Exp $");
#endif
#endif /* not lint */
@ -150,7 +150,7 @@ statf(FTSENT *p)
int fd, indent;
const char *name;
#if !defined(NO_MD5) || !defined(NO_RMD160) || !defined(NO_SHA1) || !defined(NO_SHA2)
char digestbuf[MAXHASHLEN + 1];
char *digestbuf;
#endif
indent = printf("%s%s",
@ -204,40 +204,46 @@ statf(FTSENT *p)
}
#ifndef NO_MD5
if (keys & F_MD5 && S_ISREG(p->fts_statp->st_mode)) {
if (MD5File(p->fts_accpath, digestbuf) == NULL)
if ((digestbuf = MD5File(p->fts_accpath, NULL)) == NULL)
mtree_err("%s: %s", p->fts_accpath, "MD5File");
output(&indent, "md5=%s", digestbuf);
free(digestbuf);
}
#endif /* ! NO_MD5 */
#ifndef NO_RMD160
if (keys & F_RMD160 && S_ISREG(p->fts_statp->st_mode)) {
if (RMD160File(p->fts_accpath, digestbuf) == NULL)
if ((digestbuf = RMD160File(p->fts_accpath, NULL)) == NULL)
mtree_err("%s: %s", p->fts_accpath, "RMD160File");
output(&indent, "rmd160=%s", digestbuf);
free(digestbuf);
}
#endif /* ! NO_RMD160 */
#ifndef NO_SHA1
if (keys & F_SHA1 && S_ISREG(p->fts_statp->st_mode)) {
if (SHA1File(p->fts_accpath, digestbuf) == NULL)
if ((digestbuf = SHA1File(p->fts_accpath, NULL)) == NULL)
mtree_err("%s: %s", p->fts_accpath, "SHA1File");
output(&indent, "sha1=%s", digestbuf);
free(digestbuf);
}
#endif /* ! NO_SHA1 */
#ifndef NO_SHA2
if (keys & F_SHA256 && S_ISREG(p->fts_statp->st_mode)) {
if (SHA256_File(p->fts_accpath, digestbuf) == NULL)
if ((digestbuf = SHA256_File(p->fts_accpath, NULL)) == NULL)
mtree_err("%s: %s", p->fts_accpath, "SHA256_File");
output(&indent, "sha256=%s", digestbuf);
free(digestbuf);
}
if (keys & F_SHA384 && S_ISREG(p->fts_statp->st_mode)) {
if (SHA384_File(p->fts_accpath, digestbuf) == NULL)
if ((digestbuf = SHA384_File(p->fts_accpath, NULL)) == NULL)
mtree_err("%s: %s", p->fts_accpath, "SHA384_File");
output(&indent, "sha384=%s", digestbuf);
free(digestbuf);
}
if (keys & F_SHA512 && S_ISREG(p->fts_statp->st_mode)) {
if (SHA512_File(p->fts_accpath, digestbuf) == NULL)
if ((digestbuf = SHA512_File(p->fts_accpath, NULL)) == NULL)
mtree_err("%s: %s", p->fts_accpath, "SHA512_File");
output(&indent, "sha512=%s", digestbuf);
free(digestbuf);
}
#endif /* ! NO_SHA2 */
if (keys & F_SLINK &&

View File

@ -1,4 +1,4 @@
/* $NetBSD: mtree.h,v 1.25 2006/10/14 21:14:02 christos Exp $ */
/* $NetBSD: mtree.h,v 1.26 2007/02/04 08:03:18 elad Exp $ */
/*-
* Copyright (c) 1990, 1993
@ -39,9 +39,6 @@
#define MISMATCHEXIT 2
/* Max. length of hash -- update this if needed when adding a new algorithm. */
#define MAXHASHLEN 128 /* SHA512 */
typedef struct _node {
struct _node *parent, *child; /* up, down */
struct _node *prev, *next; /* left, right */