Add wrapper functions around hash algorithm operations to avoid
undefined behavior arising from illegal function casts. As a side effect, no longer need -Wno-pointer-sign either.
This commit is contained in:
parent
2c0ecb1ab6
commit
4804dbd307
|
@ -1,4 +1,4 @@
|
|||
# $NetBSD: Makefile,v 1.25 2011/06/20 07:44:00 mrg Exp $
|
||||
# $NetBSD: Makefile,v 1.26 2011/08/06 20:46:42 dholland Exp $
|
||||
# @(#)Makefile 8.1 (Berkeley) 6/5/93
|
||||
|
||||
.include <bsd.own.mk>
|
||||
|
@ -12,8 +12,4 @@ MAN= restore.8
|
|||
MLINKS+=restore.8 rrestore.8
|
||||
.PATH: ${NETBSDSRCDIR}/sbin/dump
|
||||
|
||||
.if defined(HAVE_GCC) || defined(HAVE_PCC)
|
||||
COPTS.tape.c+= -Wno-pointer-sign
|
||||
.endif
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: restore.h,v 1.19 2011/08/06 17:01:06 dholland Exp $ */
|
||||
/* $NetBSD: restore.h,v 1.20 2011/08/06 20:46:42 dholland Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1983, 1993
|
||||
|
@ -69,10 +69,12 @@ extern int oldinofmt; /* reading tape with old format inodes */
|
|||
extern int Bcvt; /* need byte swapping on inodes and dirs */
|
||||
extern FILE *Mtreefile; /* file descriptor for the mtree file */
|
||||
|
||||
union digest_context;
|
||||
|
||||
struct digest_desc {
|
||||
const char *dd_name;
|
||||
void (*dd_init)(void *);
|
||||
void (*dd_update)(void *, const u_char *, u_int);
|
||||
void (*dd_update)(union digest_context *, const void *, u_int);
|
||||
char *(*dd_end)(void *, char *);
|
||||
};
|
||||
extern const struct digest_desc *ddesc;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: tape.c,v 1.64 2011/08/06 17:01:06 dholland Exp $ */
|
||||
/* $NetBSD: tape.c,v 1.65 2011/08/06 20:46:42 dholland Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1983, 1993
|
||||
|
@ -39,7 +39,7 @@
|
|||
#if 0
|
||||
static char sccsid[] = "@(#)tape.c 8.9 (Berkeley) 5/1/95";
|
||||
#else
|
||||
__RCSID("$NetBSD: tape.c,v 1.64 2011/08/06 17:01:06 dholland Exp $");
|
||||
__RCSID("$NetBSD: tape.c,v 1.65 2011/08/06 20:46:42 dholland Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
|
@ -94,26 +94,11 @@ int oldinofmt; /* old inode format conversion required */
|
|||
int Bcvt; /* Swap Bytes (for CCI or sun) */
|
||||
|
||||
const struct digest_desc *ddesc;
|
||||
const struct digest_desc digest_descs[] = {
|
||||
{ "MD5",
|
||||
(void (*)(void *))MD5Init,
|
||||
(void (*)(void *, const u_char *, u_int))MD5Update,
|
||||
(char *(*)(void *, char *))MD5End, },
|
||||
{ "SHA1",
|
||||
(void (*)(void *))SHA1Init,
|
||||
(void (*)(void *, const u_char *, u_int))SHA1Update,
|
||||
(char *(*)(void *, char *))SHA1End, },
|
||||
{ "RMD160",
|
||||
(void (*)(void *))RMD160Init,
|
||||
(void (*)(void *, const u_char *, u_int))RMD160Update,
|
||||
(char *(*)(void *, char *))RMD160End, },
|
||||
{ .dd_name = NULL },
|
||||
};
|
||||
|
||||
static union digest_context {
|
||||
MD5_CTX dc_md5;
|
||||
SHA1_CTX dc_sha1;
|
||||
RMD160_CTX dc_rmd160;
|
||||
MD5_CTX dc_MD5;
|
||||
SHA1_CTX dc_SHA1;
|
||||
RMD160_CTX dc_RMD160;
|
||||
} dcontext;
|
||||
|
||||
/*
|
||||
|
@ -168,6 +153,51 @@ static void xtrskip(char *, long);
|
|||
static void swap_header(struct s_spcl *);
|
||||
static void swap_old_header(struct s_ospcl *);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// thunks for type correctness
|
||||
|
||||
#define WRAP(alg) \
|
||||
static void \
|
||||
do_##alg##Init(void *ctx) \
|
||||
{ \
|
||||
alg##Init(ctx); \
|
||||
} \
|
||||
\
|
||||
static void \
|
||||
do_##alg##Update(union digest_context *ctx, \
|
||||
const void *buf, unsigned len) \
|
||||
{ \
|
||||
alg##Update(&ctx->dc_##alg, buf, len); \
|
||||
} \
|
||||
\
|
||||
static char * \
|
||||
do_##alg##End(void *ctx, char *str) \
|
||||
{ \
|
||||
return alg##End(ctx, str); \
|
||||
}
|
||||
|
||||
WRAP(MD5);
|
||||
WRAP(SHA1);
|
||||
WRAP(RMD160);
|
||||
|
||||
static const struct digest_desc digest_descs[] = {
|
||||
{ "MD5",
|
||||
do_MD5Init,
|
||||
do_MD5Update,
|
||||
do_MD5End, },
|
||||
{ "SHA1",
|
||||
do_SHA1Init,
|
||||
do_SHA1Update,
|
||||
do_SHA1End, },
|
||||
{ "RMD160",
|
||||
do_RMD160Init,
|
||||
do_RMD160Update,
|
||||
do_RMD160End, },
|
||||
{ .dd_name = NULL },
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
const struct digest_desc *
|
||||
digest_lookup(const char *name)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue