Module Name:    src
Committed By:   dholland
Date:           Sat Aug  6 20:46:42 UTC 2011

Modified Files:
        src/sbin/restore: Makefile restore.h tape.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/sbin/restore/Makefile
cvs rdiff -u -r1.19 -r1.20 src/sbin/restore/restore.h
cvs rdiff -u -r1.64 -r1.65 src/sbin/restore/tape.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/restore/Makefile
diff -u src/sbin/restore/Makefile:1.25 src/sbin/restore/Makefile:1.26
--- src/sbin/restore/Makefile:1.25	Mon Jun 20 07:44:00 2011
+++ src/sbin/restore/Makefile	Sat Aug  6 20:46:42 2011
@@ -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 @@
 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>

Index: src/sbin/restore/restore.h
diff -u src/sbin/restore/restore.h:1.19 src/sbin/restore/restore.h:1.20
--- src/sbin/restore/restore.h:1.19	Sat Aug  6 17:01:06 2011
+++ src/sbin/restore/restore.h	Sat Aug  6 20:46:42 2011
@@ -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	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;

Index: src/sbin/restore/tape.c
diff -u src/sbin/restore/tape.c:1.64 src/sbin/restore/tape.c:1.65
--- src/sbin/restore/tape.c:1.64	Sat Aug  6 17:01:06 2011
+++ src/sbin/restore/tape.c	Sat Aug  6 20:46:42 2011
@@ -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		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	 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)
 {

Reply via email to