Module Name:    src
Committed By:   agc
Date:           Wed Oct  7 04:18:47 UTC 2009

Modified Files:
        src/crypto/external/bsd/netpgp/dist/src/lib: netpgp.c packet-print.c
            packet-show.c reader.c signature.c symmetric.c validate.c writer.c

Log Message:
Clean up some Flexelint (issues pointed out by phk - many thanks!).

Also make sure the return value for each memory allocation is checked - this
is still a WIP.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 \
    src/crypto/external/bsd/netpgp/dist/src/lib/netpgp.c
cvs rdiff -u -r1.18 -r1.19 \
    src/crypto/external/bsd/netpgp/dist/src/lib/packet-print.c
cvs rdiff -u -r1.12 -r1.13 \
    src/crypto/external/bsd/netpgp/dist/src/lib/packet-show.c
cvs rdiff -u -r1.22 -r1.23 \
    src/crypto/external/bsd/netpgp/dist/src/lib/reader.c
cvs rdiff -u -r1.19 -r1.20 \
    src/crypto/external/bsd/netpgp/dist/src/lib/signature.c \
    src/crypto/external/bsd/netpgp/dist/src/lib/validate.c
cvs rdiff -u -r1.7 -r1.8 \
    src/crypto/external/bsd/netpgp/dist/src/lib/symmetric.c
cvs rdiff -u -r1.13 -r1.14 \
    src/crypto/external/bsd/netpgp/dist/src/lib/writer.c

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

Modified files:

Index: src/crypto/external/bsd/netpgp/dist/src/lib/netpgp.c
diff -u src/crypto/external/bsd/netpgp/dist/src/lib/netpgp.c:1.28 src/crypto/external/bsd/netpgp/dist/src/lib/netpgp.c:1.29
--- src/crypto/external/bsd/netpgp/dist/src/lib/netpgp.c:1.28	Tue Oct  6 02:46:17 2009
+++ src/crypto/external/bsd/netpgp/dist/src/lib/netpgp.c	Wed Oct  7 04:18:47 2009
@@ -34,7 +34,7 @@
 
 #if defined(__NetBSD__)
 __COPYRIGHT("@(#) Copyright (c) 2009 The NetBSD Foundation, Inc. All rights reserved.");
-__RCSID("$NetBSD: netpgp.c,v 1.28 2009/10/06 02:46:17 agc Exp $");
+__RCSID("$NetBSD: netpgp.c,v 1.29 2009/10/07 04:18:47 agc Exp $");
 #endif
 
 #include <sys/types.h>
@@ -153,20 +153,40 @@
 }
 
 /* check there's enough space in the arrays */
-static void
+static int
 size_arrays(netpgp_t *netpgp, unsigned needed)
 {
+	char	**temp;
+
 	if (netpgp->size == 0) {
 		/* only get here first time around */
 		netpgp->size = needed;
-		netpgp->name = calloc(sizeof(char *), needed);
-		netpgp->value = calloc(sizeof(char *), needed);
+		if ((netpgp->name = calloc(sizeof(char *), needed)) == NULL) {
+			(void) fprintf(stderr, "size_arrays: bad alloc\n");
+			return 0;
+		}
+		if ((netpgp->value = calloc(sizeof(char *), needed)) == NULL) {
+			free(netpgp->name);
+			(void) fprintf(stderr, "size_arrays: bad alloc\n");
+			return 0;
+		}
 	} else if (netpgp->c == netpgp->size) {
 		/* only uses 'needed' when filled array */
 		netpgp->size += needed;
-		netpgp->name = realloc(netpgp->name, sizeof(char *) * needed);
-		netpgp->value = realloc(netpgp->value, sizeof(char *) * needed);
+		temp = realloc(netpgp->name, sizeof(char *) * needed);
+		if (temp == NULL) {
+			(void) fprintf(stderr, "size_arrays: bad alloc\n");
+			return 0;
+		}
+		netpgp->name = temp;
+		temp = realloc(netpgp->value, sizeof(char *) * needed);
+		if (temp == NULL) {
+			(void) fprintf(stderr, "size_arrays: bad alloc\n");
+			return 0;
+		}
+		netpgp->value = temp;
 	}
+	return 1;
 }
 
 /* find the name in the array */
@@ -195,8 +215,12 @@
 		(void) snprintf(f, sizeof(f), "%s/%s.gpg", homedir, name);
 		filename = f;
 	}
-	keyring = calloc(1, sizeof(*keyring));
+	if ((keyring = calloc(1, sizeof(*keyring))) == NULL) {
+		(void) fprintf(stderr, "readkeyring: bad alloc\n");
+		return NULL;
+	}
 	if (!__ops_keyring_fileread(keyring, noarmor, filename)) {
+		free(keyring);
 		(void) fprintf(stderr, "Can't read %s %s\n", name, filename);
 		return NULL;
 	}
@@ -236,7 +260,10 @@
 #else
 	coredumps = 1;
 #endif
-	io = calloc(1, sizeof(*io));
+	if ((io = calloc(1, sizeof(*io))) == NULL) {
+		(void) fprintf(stderr, "netpgp_init: bad alloc\n");
+		return 0;
+	}
 	io->outs = stdout;
 	if ((stream = netpgp_getvar(netpgp, "stdout")) != NULL &&
 	    strcmp(stream, "stderr") == 0) {
@@ -616,6 +643,7 @@
 	__ops_io_t	*io;
 	char		 ringname[MAXPATHLEN];
 	char		*homedir;
+	int		 ret;
 
 	io = netpgp->io;
 	if (f == NULL) {
@@ -628,17 +656,23 @@
 				"%s/pubring.gpg", homedir);
 		pubringname = ringname;
 	}
-	keyring = calloc(1, sizeof(*keyring));
+	if ((keyring = calloc(1, sizeof(*keyring))) == NULL) {
+		(void) fprintf(io->errs, "netpgp_list_packets: bad alloc\n");
+		return 0;
+	}
 	if (!__ops_keyring_fileread(keyring, noarmor, pubringname)) {
+		free(keyring);
 		(void) fprintf(io->errs, "Cannot read pub keyring %s\n",
 			pubringname);
 		return 0;
 	}
 	netpgp->pubring = keyring;
 	netpgp_setvar(netpgp, "pubring", pubringname);
-	return __ops_list_packets(io, f, (unsigned)armour, keyring,
+	ret = __ops_list_packets(io, f, (unsigned)armour, keyring,
 					netpgp->passfp,
 					get_passphrase_cb);
+	free(keyring);
+	return ret;
 }
 
 /* set a variable */
@@ -649,8 +683,9 @@
 
 	if ((i = findvar(netpgp, name)) < 0) {
 		/* add the element to the array */
-		size_arrays(netpgp, netpgp->size + 15);
-		netpgp->name[i = netpgp->c++] = strdup(name);
+		if (size_arrays(netpgp, netpgp->size + 15)) {
+			netpgp->name[i = netpgp->c++] = strdup(name);
+		}
 	} else {
 		/* replace the element in the array */
 		if (netpgp->value[i]) {

Index: src/crypto/external/bsd/netpgp/dist/src/lib/packet-print.c
diff -u src/crypto/external/bsd/netpgp/dist/src/lib/packet-print.c:1.18 src/crypto/external/bsd/netpgp/dist/src/lib/packet-print.c:1.19
--- src/crypto/external/bsd/netpgp/dist/src/lib/packet-print.c:1.18	Wed Jun 10 16:36:23 2009
+++ src/crypto/external/bsd/netpgp/dist/src/lib/packet-print.c	Wed Oct  7 04:18:47 2009
@@ -58,7 +58,7 @@
 
 #if defined(__NetBSD__)
 __COPYRIGHT("@(#) Copyright (c) 2009 The NetBSD Foundation, Inc. All rights reserved.");
-__RCSID("$NetBSD: packet-print.c,v 1.18 2009/06/10 16:36:23 agc Exp $");
+__RCSID("$NetBSD: packet-print.c,v 1.19 2009/10/07 04:18:47 agc Exp $");
 #endif
 
 #include <string.h>
@@ -84,7 +84,7 @@
 static void 
 print_indent(void)
 {
-	int             i = 0;
+	int             i;
 
 	for (i = 0; i < indent; i++) {
 		printf("  ");
@@ -105,7 +105,7 @@
 {
 	print_name(name);
 
-	printf("len=%d, data=0x", len);
+	printf("len=%u, data=0x", len);
 	hexdump(stdout, data, len, "");
 	printf("\n");
 }
@@ -124,7 +124,7 @@
 print_uint(const char *name, unsigned int val)
 {
 	print_name(name);
-	printf("%d\n", val);
+	printf("%u\n", val);
 }
 
 static void 
@@ -494,13 +494,13 @@
 		printf("Symmetric algorithm: %d (%s)\n", seckey->alg,
 		       __ops_show_symm_alg(seckey->alg));
 		printf("Hash algorithm: %d (%s)\n", seckey->hash_alg,
-		       __ops_show_hash_alg(seckey->hash_alg));
+		       __ops_show_hash_alg((unsigned char)seckey->hash_alg));
 		if (seckey->s2k_specifier != OPS_S2KS_SIMPLE) {
 			print_hexdump("Salt", seckey->salt,
 					sizeof(seckey->salt));
 		}
 		if (seckey->s2k_specifier == OPS_S2KS_ITERATED_AND_SALTED) {
-			printf("Octet count: %d\n", seckey->octetc);
+			printf("Octet count: %u\n", seckey->octetc);
 		}
 		print_hexdump("IV", seckey->iv, __ops_block_size(seckey->alg));
 	}
@@ -578,7 +578,7 @@
 	indent++;
 	print_indent();
 	printf("-- %s (type 0x%02x)\n",
-	       __ops_show_ss_type(type),
+	       __ops_show_ss_type((__ops_ss_type_t)type),
 	       type - OPS_PTAG_SIG_SUBPKT_BASE);
 }
 
@@ -606,7 +606,7 @@
 	}
 	if (pkt->tag == OPS_PARSER_PTAG) {
 		printf("=> OPS_PARSER_PTAG: %s\n",
-			__ops_show_packet_tag(content->ptag.type));
+			__ops_show_packet_tag((__ops_packet_tag_t)content->ptag.type));
 	} else {
 		printf("=> %s\n", __ops_show_packet_tag(pkt->tag));
 	}
@@ -632,13 +632,13 @@
 		}
 		printf("\n");
 		print_indent();
-		printf("==== ptag new_format=%d type=%d length_type=%d"
-		       " length=0x%x (%d) position=0x%x (%d)\n",
+		printf("==== ptag new_format=%u type=%u length_type=%d"
+		       " length=0x%x (%u) position=0x%x (%u)\n",
 		       content->ptag.new_format,
 		       content->ptag.type, content->ptag.length_type,
 		       content->ptag.length, content->ptag.length,
 		       content->ptag.position, content->ptag.position);
-		print_tagname(__ops_show_packet_tag(content->ptag.type));
+		print_tagname(__ops_show_packet_tag((__ops_packet_tag_t)content->ptag.type));
 		break;
 
 	case OPS_PTAG_CT_SE_DATA_HEADER:
@@ -654,7 +654,7 @@
 	case OPS_PTAG_CT_SE_IP_DATA_BODY:
 		print_tagname(
 			"SYMMETRIC ENCRYPTED INTEGRITY PROTECTED DATA BODY");
-		printf("  data body length=%d\n",
+		printf("  data body length=%u\n",
 		       content->se_data_body.length);
 		printf("    data=");
 		hexdump(stdout, content->se_data_body.data,
@@ -704,8 +704,9 @@
 			__ops_show_pka(content->sig.info.key_alg),
 				     content->sig.info.key_alg);
 		print_string_and_value("Hash Algorithm",
-			__ops_show_hash_alg(content->sig.info.hash_alg),
-			content->sig.info.hash_alg);
+			__ops_show_hash_alg((unsigned char)
+				content->sig.info.hash_alg),
+			(unsigned char)content->sig.info.hash_alg);
 		print_uint("Hashed data len",
 			content->sig.info.v4_hashlen);
 		print_indent();
@@ -751,8 +752,8 @@
 		    __ops_show_sig_type(content->one_pass_sig.sig_type),
 				       content->one_pass_sig.sig_type);
 		print_string_and_value("Hash Algorithm",
-			__ops_show_hash_alg(content->one_pass_sig.hash_alg),
-			content->one_pass_sig.hash_alg);
+			__ops_show_hash_alg((unsigned char)content->one_pass_sig.hash_alg),
+			(unsigned char)content->one_pass_sig.hash_alg);
 		print_string_and_value("Public Key Algorithm",
 			__ops_show_pka(content->one_pass_sig.key_alg),
 			content->one_pass_sig.key_alg);
@@ -777,7 +778,7 @@
 		start_subpacket(pkt->tag);
 		print_uint("Raw Signature Subpacket: tag",
 			(unsigned)(content->ss_raw.tag -
-		   	OPS_PTAG_SIG_SUBPKT_BASE));
+		   	(unsigned)OPS_PTAG_SIG_SUBPKT_BASE));
 		print_hexdump("Raw Data",
 			      content->ss_raw.raw,
 			      content->ss_raw.length);
@@ -1016,7 +1017,7 @@
 
 	case OPS_PTAG_CT_LITDATA_BODY:
 		print_tagname("LITERAL DATA BODY");
-		printf("  literal data body length=%d\n",
+		printf("  literal data body length=%u\n",
 		       content->litdata_body.length);
 		printf("    data=");
 		print_escaped(content->litdata_body.data,
@@ -1045,8 +1046,8 @@
 			__ops_show_pka(content->sig.info.key_alg),
 				     content->sig.info.key_alg);
 		print_string_and_value("Hash Algorithm",
-			__ops_show_hash_alg(content->sig.info.hash_alg),
-			content->sig.info.hash_alg);
+			__ops_show_hash_alg((unsigned char)content->sig.info.hash_alg),
+			(unsigned char)content->sig.info.hash_alg);
 
 		break;
 
@@ -1190,7 +1191,7 @@
 	__ops_stream_t	*stream = NULL;
 	const unsigned		 accumulate = 1;
 	const int		 printerrors = 1;
-	int			 fd = 0;
+	int			 fd;
 
 	fd = __ops_setup_file_read(io, &stream, filename, NULL, cb_list_packets,
 				accumulate);

Index: src/crypto/external/bsd/netpgp/dist/src/lib/packet-show.c
diff -u src/crypto/external/bsd/netpgp/dist/src/lib/packet-show.c:1.12 src/crypto/external/bsd/netpgp/dist/src/lib/packet-show.c:1.13
--- src/crypto/external/bsd/netpgp/dist/src/lib/packet-show.c:1.12	Thu Jun 11 01:12:42 2009
+++ src/crypto/external/bsd/netpgp/dist/src/lib/packet-show.c	Wed Oct  7 04:18:47 2009
@@ -60,7 +60,7 @@
 
 #if defined(__NetBSD__)
 __COPYRIGHT("@(#) Copyright (c) 2009 The NetBSD Foundation, Inc. All rights reserved.");
-__RCSID("$NetBSD: packet-show.c,v 1.12 2009/06/11 01:12:42 agc Exp $");
+__RCSID("$NetBSD: packet-show.c,v 1.13 2009/10/07 04:18:47 agc Exp $");
 #endif
 
 #include <stdlib.h>
@@ -151,7 +151,6 @@
 
 	{0x00, NULL},		/* this is the end-of-array marker */
 };
-typedef __ops_map_t packet_tag_map_t;
 
 static __ops_map_t ss_type_map[] =
 {
@@ -176,7 +175,6 @@
 	{OPS_PTAG_SS_FEATURES, "Features"},
 	{0x00, NULL},		/* this is the end-of-array marker */
 };
-typedef __ops_map_t ss_type_map_t;
 
 
 static __ops_map_t ss_rr_code_map[] =
@@ -188,7 +186,6 @@
 	{0x20, "User ID information is no longer valid"},
 	{0x00, NULL},		/* this is the end-of-array marker */
 };
-typedef __ops_map_t ss_rr_code_map_t;
 
 static __ops_map_t sig_type_map[] =
 {
@@ -209,7 +206,6 @@
 	{OPS_SIG_3RD_PARTY, "Third-Party Confirmation signature"},
 	{0x00, NULL},		/* this is the end-of-array marker */
 };
-typedef __ops_map_t sig_type_map_t;
 
 static __ops_map_t pubkey_alg_map[] =
 {
@@ -235,7 +231,6 @@
 	{OPS_PKA_PRIVATE10, "Private/Experimental"},
 	{0x00, NULL},		/* this is the end-of-array marker */
 };
-typedef __ops_map_t pubkey_alg_map_t;
 
 static __ops_map_t symm_alg_map[] =
 {
@@ -349,29 +344,27 @@
 	 * We only resize in one direction - upwards. Algorithm used : double
 	 * the current size then add 1
 	 */
+	char	**newstrings;
+	int	  newsize;
 
-	int             newsize = 0;
-
-	newsize = list->size * 2 + 1;
-	list->strings = realloc(list->strings, newsize * sizeof(char *));
-	if (list->strings) {
+	newsize = (list->size * 2) + 1;
+	newstrings = realloc(list->strings, newsize * sizeof(char *));
+	if (newstrings) {
+		list->strings = newstrings;
 		list->size = newsize;
 		return 1;
-	} else {
-		/* xxx - realloc failed. error message? - rachel */
-		return 0;
 	}
+	/* xxx - realloc failed. error message? - rachel */
+	return 0;
 }
 
 static unsigned int 
 add_str(__ops_list_t *list, const char *str)
 {
-	if (list->size == list->used)
-		if (!list_resize(list))
-			return 0;
-
-	list->strings[list->used] = __UNCONST(str);
-	list->used++;
+	if (list->size == list->used && !list_resize(list)) {
+		return 0;
+	}
+	list->strings[list->used++] = __UNCONST(str);
 	return 1;
 }
 
@@ -414,7 +407,7 @@
 	list_free_strings(&text->unknown);
 	list_free(&text->unknown);
 
-	(void) free(text);
+	free(text);
 }
 
 /* XXX: should this (and many others) be unsigned? */
@@ -437,11 +430,15 @@
 		unsigned        len = 2 + 2 + 1;	/* 2 for "0x", 2 for
 							 * single octet in hex
 							 * format, 1 for NUL */
-		str = calloc(1, len);
+		if ((str = calloc(1, len)) == NULL) {
+			(void) fprintf(stderr, "add_str_from_octet_map: bad alloc\n");
+			return 0;
+		}
 		(void) snprintf(str, len, "0x%x", octet);
 		if (!add_str(&map->unknown, str)) {
 			return 0;
 		}
+		free(str);
 	}
 	return 1;
 }
@@ -467,13 +464,18 @@
 		 * be replaced in the output by 2 chars of hex, so the length
 		 * will be correct
 		 */
-		unsigned        len = strlen(fmt_unknown) + 1;
+		unsigned         len = strlen(fmt_unknown) + 1;
+		char		*newstr;
 
-		str = calloc(1, len);
-		(void) snprintf(__UNCONST(str), len, fmt_unknown, bit);
-		if (!add_str(&map->unknown, str)) {
+		if ((newstr = calloc(1, len)) == NULL) {
+			(void) fprintf(stderr, "add_bitmap_entry: bad alloc\n");
+			return 0;
+		}
+		(void) snprintf(newstr, len, fmt_unknown, bit);
+		if (!add_str(&map->unknown, newstr)) {
 			return 0;
 		}
+		free(newstr);
 	}
 	return 1;
 }
@@ -490,17 +492,15 @@
 text_from_bytemapped_octets(__ops_data_t *data,
 			    const char *(*text_fn)(unsigned char octet))
 {
-
-	__ops_text_t     *text = NULL;
-	const char     *str;
-	unsigned        i;
+	__ops_text_t	*text;
+	const char	*str;
+	unsigned	 i;
 
 	/*
 	 * ! allocate and initialise __ops_text_t structure to store derived
 	 * strings
 	 */
-	text = calloc(1, sizeof(__ops_text_t));
-	if (!text) {
+	if ((text = calloc(1, sizeof(*text))) == NULL) {
 		return NULL;
 	}
 
@@ -536,7 +536,7 @@
 		    size_t nmap)
 {
 	unsigned char	 mask, bit;
-	__ops_text_t	*text = NULL;
+	__ops_text_t	*text;
 	const char	*str;
 	unsigned         i;
 	int              j = 0;
@@ -545,8 +545,7 @@
 	 * ! allocate and initialise __ops_text_t structure to store derived
 	 * strings
 	 */
-	text = calloc(1, sizeof(__ops_text_t));
-	if (!text) {
+	if ((text = calloc(1, sizeof(__ops_text_t))) == NULL) {
 		return NULL;
 	}
 
@@ -762,13 +761,12 @@
 __ops_showall_ss_features(__ops_ss_features_t ss_features)
 {
 	unsigned char	 mask, bit;
-	__ops_text_t	*text = NULL;
+	__ops_text_t	*text;
 	const char	*str;
 	unsigned	 i;
-	int		 j = 0;
+	int		 j;
 
-	text = calloc(1, sizeof(__ops_text_t));
-	if (!text) {
+	if ((text = calloc(1, sizeof(*text))) == NULL) {
 		return NULL;
 	}
 
@@ -815,12 +813,11 @@
 __ops_showall_ss_key_flags(__ops_ss_key_flags_t ss_key_flags)
 {
 	unsigned char    mask, bit;
-	__ops_text_t	*text = NULL;
+	__ops_text_t	*text;
 	const char	*str;
-	int              i = 0;
+	int              i;
 
-	text = calloc(1, sizeof(__ops_text_t));
-	if (!text) {
+	if ((text = calloc(1, sizeof(*text))) == NULL) {
 		return NULL;
 	}
 
@@ -871,12 +868,11 @@
 __ops_show_keyserv_prefs(__ops_ss_key_server_prefs_t prefs)
 {
 	unsigned char	 mask, bit;
-	__ops_text_t	*text = NULL;
+	__ops_text_t	*text;
 	const char	*str;
 	int              i = 0;
 
-	text = calloc(1, sizeof(__ops_text_t));
-	if (!text) {
+	if ((text = calloc(1, sizeof(*text))) == NULL) {
 		return NULL;
 	}
 

Index: src/crypto/external/bsd/netpgp/dist/src/lib/reader.c
diff -u src/crypto/external/bsd/netpgp/dist/src/lib/reader.c:1.22 src/crypto/external/bsd/netpgp/dist/src/lib/reader.c:1.23
--- src/crypto/external/bsd/netpgp/dist/src/lib/reader.c:1.22	Sat Jun 13 05:25:09 2009
+++ src/crypto/external/bsd/netpgp/dist/src/lib/reader.c	Wed Oct  7 04:18:47 2009
@@ -54,7 +54,7 @@
 
 #if defined(__NetBSD__)
 __COPYRIGHT("@(#) Copyright (c) 2009 The NetBSD Foundation, Inc. All rights reserved.");
-__RCSID("$NetBSD: reader.c,v 1.22 2009/06/13 05:25:09 agc Exp $");
+__RCSID("$NetBSD: reader.c,v 1.23 2009/10/07 04:18:47 agc Exp $");
 #endif
 
 #include <sys/types.h>
@@ -101,7 +101,6 @@
 #endif
 
 #include <string.h>
-#include <stdarg.h>
 #include <stdlib.h>
 #include <stdio.h>
 
@@ -132,7 +131,6 @@
 #include "keyring.h"
 #include "readerwriter.h"
 #include "netpgpdefs.h"
-#include "version.h"
 #include "netpgpdigest.h"
 
 
@@ -212,7 +210,7 @@
 	__ops_reader_t *next = stream->readinfo.next;
 
 	stream->readinfo = *next;
-	(void) free(next);
+	free(next);
 }
 
 /**
@@ -231,6 +229,23 @@
 
 #define CRC24_POLY 0x1864cfbL
 
+enum {
+	NONE = 0,
+	BEGIN_PGP_MESSAGE,
+	BEGIN_PGP_PUBLIC_KEY_BLOCK,
+	BEGIN_PGP_PRIVATE_KEY_BLOCK,
+	BEGIN_PGP_MULTI,
+	BEGIN_PGP_SIGNATURE,
+
+	END_PGP_MESSAGE,
+	END_PGP_PUBLIC_KEY_BLOCK,
+	END_PGP_PRIVATE_KEY_BLOCK,
+	END_PGP_MULTI,
+	END_PGP_SIGNATURE,
+
+	BEGIN_PGP_SIGNED_MESSAGE
+};
+
 /**
  * \struct dearmour_t
  */
@@ -240,22 +255,7 @@
 		BASE64,
 		AT_TRAILER_NAME
 	} state;
-	enum {
-		NONE = 0,
-		BEGIN_PGP_MESSAGE,
-		BEGIN_PGP_PUBLIC_KEY_BLOCK,
-		BEGIN_PGP_PRIVATE_KEY_BLOCK,
-		BEGIN_PGP_MULTI,
-		BEGIN_PGP_SIGNATURE,
-
-		END_PGP_MESSAGE,
-		END_PGP_PUBLIC_KEY_BLOCK,
-		END_PGP_PRIVATE_KEY_BLOCK,
-		END_PGP_MULTI,
-		END_PGP_SIGNATURE,
-
-		BEGIN_PGP_SIGNED_MESSAGE
-	} lastseen;
+	int		lastseen;
 	__ops_stream_t *parse_info;
 	unsigned	seen_nl:1;
 	unsigned	prev_nl:1;
@@ -300,7 +300,7 @@
 	} else {
 		dearmour->pushback = calloc(1, length);
 		for (n = 0; n < length; ++n) {
-			dearmour->pushback[n] = buf[length - n - 1];
+			dearmour->pushback[n] = buf[(length - n) - 1];
 		}
 		dearmour->pushbackc = length;
 	}
@@ -425,7 +425,7 @@
 		if (dearmour->pushbackc) {
 			c = dearmour->pushback[--dearmour->pushbackc];
 			if (dearmour->pushbackc == 0) {
-				(void) free(dearmour->pushback);
+				free(dearmour->pushback);
 				dearmour->pushback = NULL;
 			}
 		} else if (__ops_stacked_read(&c, 1, errors, readinfo,
@@ -565,13 +565,13 @@
 
 		alg = __ops_str_to_hash_alg(hashstr);
 		if (!__ops_is_hash_alg_supported(&alg)) {
-			(void) free(hash);
+			free(hash);
 			OPS_ERROR_1(errors, OPS_E_R_BAD_FORMAT,
 				"Unsupported hash algorithm '%s'", hashstr);
 			return -1;
 		}
 		if (alg == OPS_HASH_UNKNOWN) {
-			(void) free(hash);
+			free(hash);
 			OPS_ERROR_1(errors, OPS_E_R_BAD_FORMAT,
 				"Unknown hash algorithm '%s'", hashstr);
 			return -1;
@@ -687,6 +687,10 @@
 		n = dearmour->headers.headerc;
 		dearmour->headers.headers = realloc(dearmour->headers.headers,
 				(n + 1) * sizeof(*dearmour->headers.headers));
+		if (dearmour->headers.headers == NULL) {
+			(void) fprintf(stderr, "add_header: bad alloc\n");
+			return 0;
+		}
 		dearmour->headers.headers[n].key = strdup(key);
 		dearmour->headers.headers[n].value = strdup(value);
 		dearmour->headers.headerc = n + 1;
@@ -702,13 +706,16 @@
 {
 	unsigned        nbuf;
 	unsigned        size;
+	unsigned	first = 1;
 	char           *buf;
-	unsigned   		first = 1;
 	int             ret = 1;
 
-	buf = NULL;
-	nbuf = size = 0;
-
+	nbuf = 0;
+	size = 80;
+	if ((buf = calloc(1, size)) == NULL) {
+		(void) fprintf(stderr, "parse_headers: bad calloc\n");
+		return -1;
+	}
 	for (;;) {
 		int             c;
 
@@ -731,8 +738,7 @@
 			}
 			buf[nbuf] = '\0';
 
-			s = strchr(buf, ':');
-			if (!s) {
+			if ((s = strchr(buf, ':')) == NULL) {
 				if (!first && !dearmour->allow_headers_without_gap) {
 					/*
 					 * then we have seriously malformed
@@ -776,13 +782,18 @@
 			if (size <= nbuf + 1) {
 				size += size + 80;
 				buf = realloc(buf, size);
+				if (buf == NULL) {
+					(void) fprintf(stderr, "bad alloc\n");
+					ret = -1;
+					goto end;
+				}
 			}
 			buf[nbuf++] = c;
 		}
 	}
 
 end:
-	(void) free(buf);
+	free(buf);
 
 	return ret;
 }
@@ -806,11 +817,11 @@
 		}
 		l <<= 6;
 		if (c >= 'A' && c <= 'Z') {
-			l += c - 'A';
+			l += (unsigned long)(c - 'A');
 		} else if (c >= 'a' && c <= 'z') {
-			l += c - 'a' + 26;
+			l += (unsigned long)(c - 'a') + 26;
 		} else if (c >= '0' && c <= '9') {
-			l += c - '0' + 52;
+			l += (unsigned long)(c - '0') + 52;
 		} else if (c == '+') {
 			l += 62;
 		} else if (c == '/') {
@@ -1121,8 +1132,8 @@
 
 			if (strcmp(buf, "BEGIN PGP SIGNED MESSAGE") == 0) {
 				__ops_dup_headers(
-				&content.u.cleartext_head.headers,
-				&dearmour->headers);
+					&content.u.cleartext_head.headers,
+					&dearmour->headers);
 				CALLBACK(OPS_PTAG_CT_SIGNED_CLEARTEXT_HEADER,
 					cbinfo,
 					&content);
@@ -1132,6 +1143,8 @@
 					return ret;
 				}
 			} else {
+				/* XXX Flexelint -  Assigning address of auto variable 'buf' to outer
+				    scope symbol 'content'*/
 				content.u.armour_header.type = buf;
 				content.u.armour_header.headers =
 						dearmour->headers;
@@ -1271,7 +1284,7 @@
 static void 
 armoured_data_destroyer(__ops_reader_t *readinfo)
 {
-	(void) free(__ops_reader_get_arg(readinfo));
+	free(__ops_reader_get_arg(readinfo));
 }
 
 /**
@@ -1326,7 +1339,7 @@
 	dearmour_t *dearmour;
 
 	dearmour = __ops_reader_get_arg(__ops_readinfo(stream));
-	(void) free(dearmour);
+	free(dearmour);
 	__ops_reader_pop(stream);
 }
 
@@ -1470,7 +1483,7 @@
 static void 
 encrypted_data_destroyer(__ops_reader_t *readinfo)
 {
-	(void) free(__ops_reader_get_arg(readinfo));
+	free(__ops_reader_get_arg(readinfo));
 }
 
 /**
@@ -1504,7 +1517,7 @@
 
 	encrypted = __ops_reader_get_arg(__ops_readinfo(stream));
 	encrypted->decrypt->decrypt_finish(encrypted->decrypt);
-	(void) free(encrypted);
+	free(encrypted);
 	__ops_reader_pop(stream);
 }
 
@@ -1513,12 +1526,12 @@
 typedef struct {
 	/* boolean: 0 once we've done the preamble/MDC checks */
 	/* and are reading from the plaintext */
-	int             passed_checks;
-	unsigned char  *plaintext;
-	size_t          plaintext_available;
-	size_t          plaintext_offset;
-	__ops_region_t   *region;
-	__ops_crypt_t    *decrypt;
+	int              passed_checks;
+	unsigned char	*plaintext;
+	size_t           plaintext_available;
+	size_t           plaintext_offset;
+	__ops_region_t	*region;
+	__ops_crypt_t	*decrypt;
 } decrypt_se_ip_t;
 
 /*
@@ -1541,17 +1554,17 @@
 	se_ip = __ops_reader_get_arg(readinfo);
 	if (!se_ip->passed_checks) {
 		unsigned char  *buf = NULL;
-		__ops_hash_t      hash;
 		unsigned char   hashed[OPS_SHA1_HASH_SIZE];
+		unsigned char  *preamble;
+		unsigned char  *plaintext;
+		unsigned char  *mdc;
+		unsigned char  *mdc_hash;
+		__ops_hash_t	hash;
 		size_t          b;
 		size_t          sz_preamble;
 		size_t          sz_mdc_hash;
 		size_t          sz_mdc;
 		size_t          sz_plaintext;
-		unsigned char  *preamble;
-		unsigned char  *plaintext;
-		unsigned char  *mdc;
-		unsigned char  *mdc_hash;
 
 		__ops_hash_any(&hash, OPS_HASH_SHA1);
 		hash.init(&hash);
@@ -1564,11 +1577,11 @@
 		/* read entire SE IP packet */
 		if (!__ops_stacked_limited_read(buf, decrypted_region.length,
 				&decrypted_region, errors, readinfo, cbinfo)) {
-			(void) free(buf);
+			free(buf);
 			return -1;
 		}
 		if (__ops_get_debug_level(__FILE__)) {
-			unsigned int    i = 0;
+			unsigned	i;
 
 			fprintf(stderr, "\n\nentire SE IP packet (len=%d):\n",
 					decrypted_region.length);
@@ -1583,7 +1596,8 @@
 		/* verify leading preamble */
 
 		if (__ops_get_debug_level(__FILE__)) {
-			unsigned int    i = 0;
+			unsigned	i;
+
 			fprintf(stderr, "\npreamble: ");
 			for (i = 0; i < se_ip->decrypt->blocksize + 2; i++)
 				fprintf(stderr, " 0x%02x", buf[i]);
@@ -1596,7 +1610,7 @@
 				buf[b - 2], buf[b - 1], buf[b], buf[b + 1]);
 			OPS_ERROR(errors, OPS_E_PROTO_BAD_SYMMETRIC_DECRYPT,
 			"Bad symmetric decrypt when parsing SE IP packet");
-			(void) free(buf);
+			free(buf);
 			return -1;
 		}
 		/* Verify trailing MDC hash */
@@ -1604,7 +1618,7 @@
 		sz_preamble = se_ip->decrypt->blocksize + 2;
 		sz_mdc_hash = OPS_SHA1_HASH_SIZE;
 		sz_mdc = 1 + 1 + sz_mdc_hash;
-		sz_plaintext = decrypted_region.length - sz_preamble - sz_mdc;
+		sz_plaintext = (decrypted_region.length - sz_preamble) - sz_mdc;
 
 		preamble = buf;
 		plaintext = buf + sz_preamble;
@@ -1612,7 +1626,7 @@
 		mdc_hash = mdc + 2;
 
 		if (__ops_get_debug_level(__FILE__)) {
-			unsigned int    i = 0;
+			unsigned	i;
 
 			fprintf(stderr, "\nplaintext (len=%" PRIsize "u): ",
 				sz_plaintext);
@@ -1631,7 +1645,7 @@
 		if (memcmp(mdc_hash, hashed, OPS_SHA1_HASH_SIZE) != 0) {
 			OPS_ERROR(errors, OPS_E_V_BAD_HASH,
 					"Bad hash in MDC packet");
-			(void) free(buf);
+			free(buf);
 			return 0;
 		}
 		/* all done with the checks */
@@ -1647,7 +1661,7 @@
 
 		se_ip->passed_checks = 1;
 
-		(void) free(buf);
+		free(buf);
 	}
 	n = len;
 	if (n > se_ip->plaintext_available) {
@@ -1657,7 +1671,7 @@
 	memcpy(dest_, se_ip->plaintext + se_ip->plaintext_offset, n);
 	se_ip->plaintext_available -= n;
 	se_ip->plaintext_offset += n;
-	len -= n;
+	/* len -= n; - not used at all, for info only */
 
 	return n;
 }
@@ -1668,8 +1682,8 @@
 	decrypt_se_ip_t	*se_ip;
 
 	se_ip = __ops_reader_get_arg(readinfo);
-	(void) free(se_ip->plaintext);
-	(void) free(se_ip);
+	free(se_ip->plaintext);
+	free(se_ip);
 }
 
 /**
@@ -1697,7 +1711,7 @@
 	 * decrypt_se_ip_t
 	 * *se_ip=__ops_reader_get_arg(__ops_readinfo(stream));
 	 */
-	/* (void) free(se_ip); */
+	/* free(se_ip); */
 	__ops_reader_pop(stream);
 }
 
@@ -1751,7 +1765,7 @@
 static void 
 reader_fd_destroyer(__ops_reader_t *readinfo)
 {
-	(void) free(__ops_reader_get_arg(readinfo));
+	free(__ops_reader_get_arg(readinfo));
 }
 
 /**
@@ -1803,7 +1817,7 @@
 static void 
 mem_destroyer(__ops_reader_t *readinfo)
 {
-	(void) free(__ops_reader_get_arg(readinfo));
+	free(__ops_reader_get_arg(readinfo));
 }
 
 /**
@@ -2078,8 +2092,8 @@
 		/* if writer enabled, use it */
 		if (cbinfo->output) {
 			if (__ops_get_debug_level(__FILE__)) {
-				printf("litdata_cb: length is %d\n",
-				  content->litdata_body.length);
+				printf("litdata_cb: length is %u\n",
+					content->litdata_body.length);
 			}
 			__ops_write(cbinfo->output,
 					content->litdata_body.data,
@@ -2117,7 +2131,7 @@
 		if (!cbinfo->cryptinfo.keyring) {
 			(void) fprintf(io->errs,
 				"pk_sesskey_cb: bad keyring\n");
-			return 0;
+			return (__ops_cb_ret_t)0;
 		}
 		cbinfo->cryptinfo.keydata =
 			__ops_getkeybyid(io, cbinfo->cryptinfo.keyring,
@@ -2167,7 +2181,7 @@
 				content->get_seckey.pk_sesskey->key_id);
 		if (!cbinfo->cryptinfo.keydata ||
 		    !__ops_is_key_secret(cbinfo->cryptinfo.keydata)) {
-			return 0;
+			return (__ops_cb_ret_t)0;
 		}
 
 		keypair = cbinfo->cryptinfo.keydata;
@@ -2296,7 +2310,7 @@
 
 	(void) munmap(mem->mem, (unsigned)mem->size);
 	(void) close(mem->fd);
-	(void) free(__ops_reader_get_arg(readinfo));
+	free(__ops_reader_get_arg(readinfo));
 }
 
 /* set up the file to use mmap-ed memory if available, file IO otherwise */
@@ -2307,11 +2321,11 @@
 	struct stat	 st;
 
 	if (fstat(fd, &st) == 0) {
-		mem->size = st.st_size;
+		mem->size = (uint64_t)st.st_size;
 		mem->offset = 0;
 		mem->fd = fd;
 		mem->mem = mmap(NULL, (size_t)st.st_size, PROT_READ,
-				MAP_FILE | MAP_PRIVATE, fd, 0);
+				MAP_PRIVATE | MAP_FILE, fd, 0);
 		if (mem->mem == MAP_FAILED) {
 			__ops_reader_set(stream, fd_reader, reader_fd_destroyer,
 					mem);

Index: src/crypto/external/bsd/netpgp/dist/src/lib/signature.c
diff -u src/crypto/external/bsd/netpgp/dist/src/lib/signature.c:1.19 src/crypto/external/bsd/netpgp/dist/src/lib/signature.c:1.20
--- src/crypto/external/bsd/netpgp/dist/src/lib/signature.c:1.19	Thu Jun 11 01:12:42 2009
+++ src/crypto/external/bsd/netpgp/dist/src/lib/signature.c	Wed Oct  7 04:18:47 2009
@@ -57,7 +57,7 @@
 
 #if defined(__NetBSD__)
 __COPYRIGHT("@(#) Copyright (c) 2009 The NetBSD Foundation, Inc. All rights reserved.");
-__RCSID("$NetBSD: signature.c,v 1.19 2009/06/11 01:12:42 agc Exp $");
+__RCSID("$NetBSD: signature.c,v 1.20 2009/10/07 04:18:47 agc Exp $");
 #endif
 
 #include <sys/types.h>
@@ -924,11 +924,15 @@
 		unsigned        flen = strlen(inname) + 4 + 1;
 		char           *f = NULL;
 
-		f = calloc(1, flen);
-		(void) snprintf(f, flen, "%s.%s", inname,
+		if ((f = calloc(1, flen)) == NULL) {
+			(void) fprintf(stderr, "open_output_file: bad alloc\n");
+			fd = -1;
+		} else {
+			(void) snprintf(f, flen, "%s.%s", inname,
 					(armored) ? "asc" : "gpg");
-		fd = __ops_setup_file_write(output, f, overwrite);
-		(void) free(f);
+			fd = __ops_setup_file_write(output, f, overwrite);
+			free(f);
+		}
 	}
 	return fd;
 }
Index: src/crypto/external/bsd/netpgp/dist/src/lib/validate.c
diff -u src/crypto/external/bsd/netpgp/dist/src/lib/validate.c:1.19 src/crypto/external/bsd/netpgp/dist/src/lib/validate.c:1.20
--- src/crypto/external/bsd/netpgp/dist/src/lib/validate.c:1.19	Thu Jun 11 01:12:42 2009
+++ src/crypto/external/bsd/netpgp/dist/src/lib/validate.c	Wed Oct  7 04:18:47 2009
@@ -54,7 +54,7 @@
 
 #if defined(__NetBSD__)
 __COPYRIGHT("@(#) Copyright (c) 2009 The NetBSD Foundation, Inc. All rights reserved.");
-__RCSID("$NetBSD: validate.c,v 1.19 2009/06/11 01:12:42 agc Exp $");
+__RCSID("$NetBSD: validate.c,v 1.20 2009/10/07 04:18:47 agc Exp $");
 #endif
 
 #include <sys/types.h>
@@ -100,7 +100,7 @@
 	unsigned char   trailer[6];
 	unsigned int    hashedlen;
 	__ops_hash_t	hash;
-	unsigned	n = 0;
+	unsigned	n;
 
 	__OPS_USED(signer);
 	__ops_hash_any(&hash, sig->info.hash_alg);
@@ -180,30 +180,40 @@
 static void 
 free_sig_info(__ops_sig_info_t *sig)
 {
-	(void) free(sig->v4_hashed);
-	(void) free(sig);
+	free(sig->v4_hashed);
+	free(sig);
 }
 
 static void 
 copy_sig_info(__ops_sig_info_t *dst, const __ops_sig_info_t *src)
 {
 	(void) memcpy(dst, src, sizeof(*src));
-	dst->v4_hashed = calloc(1, src->v4_hashlen);
-	(void) memcpy(dst->v4_hashed, src->v4_hashed, src->v4_hashlen);
+	if ((dst->v4_hashed = calloc(1, src->v4_hashlen)) == NULL) {
+		(void) fprintf(stderr, "copy_sig_info: bad alloc\n");
+	} else {
+		(void) memcpy(dst->v4_hashed, src->v4_hashed, src->v4_hashlen);
+	}
 }
 
-static void 
+static int 
 add_sig_to_list(const __ops_sig_info_t *sig, __ops_sig_info_t **sigs,
 			unsigned *count)
 {
+	__ops_sig_info_t	*newsigs;
+
 	if (*count == 0) {
-		*sigs = calloc(*count + 1, sizeof(__ops_sig_info_t));
+		newsigs = calloc(*count + 1, sizeof(__ops_sig_info_t));
 	} else {
-		*sigs = realloc(*sigs,
+		newsigs = realloc(*sigs,
 				(*count + 1) * sizeof(__ops_sig_info_t));
 	}
-	copy_sig_info(&(*sigs)[*count], sig);
-	*count += 1;
+	if (newsigs != NULL) {
+		*sigs = newsigs;
+		copy_sig_info(&(*sigs)[*count], sig);
+		*count += 1;
+		return 1;
+	}
+	return 0;
 }
 
 
@@ -275,9 +285,13 @@
 		signer = __ops_getkeybyid(io, key->keyring,
 					 content->sig.info.signer_id);
 		if (!signer) {
-			add_sig_to_list(&content->sig.info,
-					&key->result->unknown_sigs,
-					&key->result->unknownc);
+			if (!add_sig_to_list(&content->sig.info,
+				&key->result->unknown_sigs,
+				&key->result->unknownc)) {
+					(void) fprintf(io->errs,
+					"__ops_validate_key_cb: user attribute length 0");
+					return OPS_FINISHED;
+			}
 			break;
 		}
 		switch (content->sig.info.type) {
@@ -340,14 +354,20 @@
 		}
 
 		if (valid) {
-			add_sig_to_list(&content->sig.info,
+			if (!add_sig_to_list(&content->sig.info,
 				&key->result->valid_sigs,
-				&key->result->validc);
+				&key->result->validc)) {
+				OPS_ERROR(errors, OPS_E_UNIMPLEMENTED,
+				    "Can't add good sig to list\n");
+			}
 		} else {
 			OPS_ERROR(errors, OPS_E_V_BAD_SIGNATURE, "Bad Sig");
-			add_sig_to_list(&content->sig.info,
-					&key->result->invalid_sigs,
-					&key->result->invalidc);
+			if (!add_sig_to_list(&content->sig.info,
+				&key->result->invalid_sigs,
+				&key->result->invalidc)) {
+				OPS_ERROR(errors, OPS_E_UNIMPLEMENTED,
+				    "Can't add good sig to list\n");
+			}
 		}
 		break;
 
@@ -435,9 +455,12 @@
 		if (!signer) {
 			OPS_ERROR(errors, OPS_E_V_UNKNOWN_SIGNER,
 					"Unknown Signer");
-			add_sig_to_list(&content->sig.info,
+			if (!add_sig_to_list(&content->sig.info,
 					&data->result->unknown_sigs,
-					&data->result->unknownc);
+					&data->result->unknownc)) {
+				OPS_ERROR(errors, OPS_E_V_UNKNOWN_SIGNER,
+					"Can't add unknown sig to list");
+			}
 			break;
 		}
 		switch (content->sig.info.type) {
@@ -468,15 +491,21 @@
 		}
 
 		if (valid) {
-			add_sig_to_list(&content->sig.info,
+			if (!add_sig_to_list(&content->sig.info,
 					&data->result->valid_sigs,
-					&data->result->validc);
+					&data->result->validc)) {
+				OPS_ERROR(errors, OPS_E_V_BAD_SIGNATURE,
+					"Can't add good sig to list");
+			}
 		} else {
 			OPS_ERROR(errors, OPS_E_V_BAD_SIGNATURE,
 					"Bad Signature");
-			add_sig_to_list(&content->sig.info,
+			if (!add_sig_to_list(&content->sig.info,
 					&data->result->invalid_sigs,
-					&data->result->invalidc);
+					&data->result->invalidc)) {
+				OPS_ERROR(errors, OPS_E_V_BAD_SIGNATURE,
+					"Can't add good sig to list");
+			}
 		}
 		break;
 
@@ -501,18 +530,22 @@
 static void 
 keydata_destroyer(__ops_reader_t *readinfo)
 {
-	(void) free(__ops_reader_get_arg(readinfo));
+	free(__ops_reader_get_arg(readinfo));
 }
 
 void 
 __ops_keydata_reader_set(__ops_stream_t *stream, const __ops_key_t *key)
 {
-	validate_reader_t *data = calloc(1, sizeof(*data));
+	validate_reader_t *data;
 
-	data->key = key;
-	data->packet = 0;
-	data->offset = 0;
-	__ops_reader_set(stream, keydata_reader, keydata_destroyer, data);
+	if ((data = calloc(1, sizeof(*data))) == NULL) {
+		(void) fprintf(stderr, "__ops_keydata_reader_set: bad alloc\n");
+	} else {
+		data->key = key;
+		data->packet = 0;
+		data->offset = 0;
+		__ops_reader_set(stream, keydata_reader, keydata_destroyer, data);
+	}
 }
 
 /**
@@ -624,8 +657,8 @@
 		if (result->unknown_sigs) {
 			free_sig_info(result->unknown_sigs);
 		}
-		(void) free(result);
-		result = NULL;
+		free(result);
+		/* result = NULL; - XXX unnecessary */
 	}
 }
 
@@ -652,7 +685,7 @@
 			const __ops_keyring_t *keyring)
 {
 	validate_data_cb_t	 validation;
-	__ops_stream_t	*parse = NULL;
+	__ops_stream_t		*parse = NULL;
 	struct stat		 st;
 	const int		 printerrors = 1;
 	unsigned		 ret;

Index: src/crypto/external/bsd/netpgp/dist/src/lib/symmetric.c
diff -u src/crypto/external/bsd/netpgp/dist/src/lib/symmetric.c:1.7 src/crypto/external/bsd/netpgp/dist/src/lib/symmetric.c:1.8
--- src/crypto/external/bsd/netpgp/dist/src/lib/symmetric.c:1.7	Wed May 27 00:38:27 2009
+++ src/crypto/external/bsd/netpgp/dist/src/lib/symmetric.c	Wed Oct  7 04:18:47 2009
@@ -54,7 +54,7 @@
 
 #if defined(__NetBSD__)
 __COPYRIGHT("@(#) Copyright (c) 2009 The NetBSD Foundation, Inc. All rights reserved.");
-__RCSID("$NetBSD: symmetric.c,v 1.7 2009/05/27 00:38:27 agc Exp $");
+__RCSID("$NetBSD: symmetric.c,v 1.8 2009/10/07 04:18:47 agc Exp $");
 #endif
 
 #include "crypto.h"
@@ -126,7 +126,7 @@
 cast5_init(__ops_crypt_t *crypt)
 {
 	if (crypt->encrypt_key) {
-		(void) free(crypt->encrypt_key);
+		free(crypt->encrypt_key);
 	}
 	crypt->encrypt_key = calloc(1, sizeof(CAST_KEY));
 	CAST_set_key(crypt->encrypt_key, (int)crypt->keysize, crypt->key);
@@ -191,7 +191,7 @@
 	}
 
 	if (crypt->encrypt_key) {
-		(void) free(crypt->encrypt_key);
+		free(crypt->encrypt_key);
 	}
 	crypt->encrypt_key = calloc(1, sizeof(IDEA_KEY_SCHEDULE));
 
@@ -199,7 +199,7 @@
 	idea_set_encrypt_key(crypt->key, crypt->encrypt_key);
 
 	if (crypt->decrypt_key) {
-		(void) free(crypt->decrypt_key);
+		free(crypt->decrypt_key);
 	}
 	crypt->decrypt_key = calloc(1, sizeof(IDEA_KEY_SCHEDULE));
 
@@ -260,7 +260,7 @@
 aes128_init(__ops_crypt_t *crypt)
 {
 	if (crypt->encrypt_key) {
-		(void) free(crypt->encrypt_key);
+		free(crypt->encrypt_key);
 	}
 	crypt->encrypt_key = calloc(1, sizeof(AES_KEY));
 	if (AES_set_encrypt_key(crypt->key, KEYBITS_AES128,
@@ -269,7 +269,7 @@
 	}
 
 	if (crypt->decrypt_key) {
-		(void) free(crypt->decrypt_key);
+		free(crypt->decrypt_key);
 	}
 	crypt->decrypt_key = calloc(1, sizeof(AES_KEY));
 	if (AES_set_decrypt_key(crypt->key, KEYBITS_AES128,
@@ -331,7 +331,7 @@
 aes256_init(__ops_crypt_t *crypt)
 {
 	if (crypt->encrypt_key) {
-		(void) free(crypt->encrypt_key);
+		free(crypt->encrypt_key);
 	}
 	crypt->encrypt_key = calloc(1, sizeof(AES_KEY));
 	if (AES_set_encrypt_key(crypt->key, KEYBITS_AES256,
@@ -374,7 +374,7 @@
 	int             n;
 
 	if (crypt->encrypt_key) {
-		(void) free(crypt->encrypt_key);
+		free(crypt->encrypt_key);
 	}
 	keys = crypt->encrypt_key = calloc(1, 3 * sizeof(DES_key_schedule));
 
@@ -542,7 +542,7 @@
 		*out++ = t ^ (decrypt->civ[decrypt->num++] = *in++);
 	}
 
-	return saved;
+	return (size_t)saved;
 }
 
 size_t 
@@ -570,7 +570,7 @@
 		++encrypt->num;
 	}
 
-	return saved;
+	return (size_t)saved;
 }
 
 /**

Index: src/crypto/external/bsd/netpgp/dist/src/lib/writer.c
diff -u src/crypto/external/bsd/netpgp/dist/src/lib/writer.c:1.13 src/crypto/external/bsd/netpgp/dist/src/lib/writer.c:1.14
--- src/crypto/external/bsd/netpgp/dist/src/lib/writer.c:1.13	Sat Jun 13 05:25:09 2009
+++ src/crypto/external/bsd/netpgp/dist/src/lib/writer.c	Wed Oct  7 04:18:47 2009
@@ -58,19 +58,11 @@
 
 #if defined(__NetBSD__)
 __COPYRIGHT("@(#) Copyright (c) 2009 The NetBSD Foundation, Inc. All rights reserved.");
-__RCSID("$NetBSD: writer.c,v 1.13 2009/06/13 05:25:09 agc Exp $");
+__RCSID("$NetBSD: writer.c,v 1.14 2009/10/07 04:18:47 agc Exp $");
 #endif
 
 #include <sys/types.h>
 
-#ifdef HAVE_SYS_UIO_H
-#include <sys/uio.h>
-#endif
-
-#ifdef HAVE_FCNTL_H
-#include <fcntl.h>
-#endif
-
 #include <stdlib.h>
 #include <string.h>
 
@@ -290,9 +282,11 @@
 		__ops_writer_destroyer_t *destroyer,
 		void *arg)
 {
-	__ops_writer_t *copy = calloc(1, sizeof(*copy));
+	__ops_writer_t *copy;
 
-	if (output->writer.writer == NULL) {
+	if ((copy = calloc(1, sizeof(*copy))) == NULL) {
+		(void) fprintf(stderr, "__ops_writer_push: bad alloc\n");
+	} else if (output->writer.writer == NULL) {
 		(void) fprintf(stderr, "__ops_writer_push: no orig writer\n");
 	} else {
 		*copy = output->writer;
@@ -386,7 +380,7 @@
 static void 
 generic_destroyer(__ops_writer_t *writer)
 {
-	(void) free(__ops_writer_get_arg(writer));
+	free(__ops_writer_get_arg(writer));
 }
 
 /**
@@ -428,7 +422,7 @@
 	if (__ops_get_debug_level(__FILE__)) {
 		unsigned int    i = 0;
 
-		(void) fprintf(stderr, "dash_esc_writer writing %d:\n", len);
+		(void) fprintf(stderr, "dash_esc_writer writing %u:\n", len);
 		for (i = 0; i < len; i++) {
 			fprintf(stderr, "0x%02x ", src[i]);
 			if (((i + 1) % 16) == 0) {
@@ -491,7 +485,7 @@
 
 	dash = __ops_writer_get_arg(writer);
 	__ops_memory_free(dash->trailing);
-	(void) free(dash);
+	free(dash);
 }
 
 /**
@@ -505,10 +499,15 @@
 {
 	static const char     header[] =
 		"-----BEGIN PGP SIGNED MESSAGE-----\r\nHash: ";
-	const char     *hash = __ops_text_from_hash(__ops_sig_get_hash(sig));
-	dashesc_t      *dash = calloc(1, sizeof(*dash));
+	const char     *hash;
+	dashesc_t      *dash;
 	unsigned	ret;
 
+	hash = __ops_text_from_hash(__ops_sig_get_hash(sig));
+	if ((dash = calloc(1, sizeof(*dash))) == NULL) {
+		OPS_ERROR(&output->errors, OPS_E_W, "Bad alloc");
+		return 0;
+	}
 	ret = (__ops_write(output, header, sizeof(header) - 1) &&
 		__ops_write(output, hash, strlen(hash)) &&
 		__ops_write(output, "\r\n\r\n", 4));
@@ -682,7 +681,8 @@
 			"\r\n-----BEGIN PGP SIGNATURE-----\r\nVersion: "
 			NETPGP_VERSION_STRING
 			"\r\n\r\n";
-	base64_t   *base64;
+	linebreak_t	*linebreak;
+	base64_t   	*base64;
 
 	__ops_writer_pop(output);
 	if (__ops_write(output, header, sizeof(header) - 1) == 0) {
@@ -690,9 +690,14 @@
 			"Error switching to armoured signature");
 		return 0;
 	}
+	if ((linebreak = calloc(1, sizeof(*linebreak))) == NULL) {
+		OPS_ERROR(&output->errors, OPS_E_W,
+			"__ops_writer_use_armored_sig: Bad alloc");
+		return 0;
+	}
 	__ops_writer_push(output, linebreak_writer, NULL,
 			generic_destroyer,
-			calloc(1, sizeof(linebreak_t)));
+			linebreak);
 	base64 = calloc(1, sizeof(*base64));
 	if (!base64) {
 		OPS_MEMORY_ERROR(&output->errors);
@@ -758,10 +763,14 @@
 
 	__ops_write(output, header, sizeof(header) - 1);
 	__ops_write(output, "\r\n", 2);
-	base64 = calloc(1, sizeof(*base64));
-	base64->checksum = CRC24_INIT;
-	__ops_writer_push(output, base64_writer, armoured_message_finaliser,
-		generic_destroyer, base64);
+	if ((base64 = calloc(1, sizeof(*base64))) == NULL) {
+		(void) fprintf(stderr, "__ops_writer_push_armor_msg: bad alloc\n");
+	} else {
+		base64->checksum = CRC24_INIT;
+		__ops_writer_push(output, base64_writer,
+			armoured_message_finaliser, generic_destroyer,
+			base64);
+	}
 }
 
 static unsigned 
@@ -854,6 +863,7 @@
 	unsigned int    sz_hdr = 0;
 	unsigned	(*finaliser) (__ops_error_t **, __ops_writer_t *);
 	base64_t	*base64;
+	linebreak_t	*linebreak;
 	char           *header = NULL;
 
 	finaliser = NULL;
@@ -875,11 +885,20 @@
 			"__ops_writer_push_armoured: unusual type\n");
 		return;
 	}
+	if ((linebreak = calloc(1, sizeof(*linebreak))) == NULL) {
+		(void) fprintf(stderr,
+			"__ops_writer_push_armoured: bad alloc\n");
+		return;
+	}
 	__ops_write(output, header, sz_hdr);
 	__ops_writer_push(output, linebreak_writer, NULL,
 			generic_destroyer,
-			calloc(1, sizeof(linebreak_t)));
-	base64 = calloc(1, sizeof(*base64));
+			linebreak);
+	if ((base64 = calloc(1, sizeof(*base64))) == NULL) {
+		(void) fprintf(stderr,
+			"__ops_writer_push_armoured: bad alloc\n");
+		return;
+	}
 	base64->checksum = CRC24_INIT;
 	__ops_writer_push(output, base64_writer, finaliser,
 			generic_destroyer, base64);
@@ -955,9 +974,9 @@
 	crypt_t    *pgp_encrypt = (crypt_t *) __ops_writer_get_arg(writer);
 
 	if (pgp_encrypt->free_crypt) {
-		(void) free(pgp_encrypt->crypt);
+		free(pgp_encrypt->crypt);
 	}
-	(void) free(pgp_encrypt);
+	free(pgp_encrypt);
 }
 
 /**
@@ -971,13 +990,16 @@
 	/* Remember to free this in the destroyer */
 	crypt_t    *pgp_encrypt;
 
-	pgp_encrypt = calloc(1, sizeof(*pgp_encrypt));
-	/* Setup the encrypt */
-	pgp_encrypt->crypt = pgp_crypt;
-	pgp_encrypt->free_crypt = 0;
-	/* And push writer on stack */
-	__ops_writer_push(output, encrypt_writer, NULL, encrypt_destroyer,
-			pgp_encrypt);
+	if ((pgp_encrypt = calloc(1, sizeof(*pgp_encrypt))) == NULL) {
+		(void) fprintf(stderr, "__ops_push_enc_crypt: bad alloc\n");
+	} else {
+		/* Setup the encrypt */
+		pgp_encrypt->crypt = pgp_crypt;
+		pgp_encrypt->free_crypt = 0;
+		/* And push writer on stack */
+		__ops_writer_push(output, encrypt_writer, NULL,
+			encrypt_destroyer, pgp_encrypt);
+	}
 }
 
 /**************************************************************************/
@@ -1001,23 +1023,35 @@
 void 
 __ops_push_enc_se_ip(__ops_output_t *output, const __ops_key_t *pubkey)
 {
-	unsigned char	*iv = NULL;
+	unsigned char	*iv;
 	__ops_crypt_t	*encrypted;
-
 	/* Create se_ip to be used with this writer */
 	/* Remember to free this in the destroyer */
-	encrypt_se_ip_t *se_ip = calloc(1, sizeof(*se_ip));
-
+	encrypt_se_ip_t *se_ip;
 	__ops_pk_sesskey_t *encrypted_pk_sesskey;
 
+	if ((se_ip = calloc(1, sizeof(*se_ip))) == NULL) {
+		(void) fprintf(stderr, "__ops_push_enc_se_ip: bad alloc\n");
+		return;
+	}
+
 	/* Create and write encrypted PK session key */
 	encrypted_pk_sesskey = __ops_create_pk_sesskey(pubkey);
 	__ops_write_pk_sesskey(output, encrypted_pk_sesskey);
 
 	/* Setup the se_ip */
-	encrypted = calloc(1, sizeof(*encrypted));
+	if ((encrypted = calloc(1, sizeof(*encrypted))) == NULL) {
+		free(se_ip);
+		(void) fprintf(stderr, "__ops_push_enc_se_ip: bad alloc\n");
+		return;
+	}
 	__ops_crypt_any(encrypted, encrypted_pk_sesskey->symm_alg);
-	iv = calloc(1, encrypted->blocksize);
+	if ((iv = calloc(1, encrypted->blocksize)) == NULL) {
+		free(se_ip);
+		free(encrypted);
+		(void) fprintf(stderr, "__ops_push_enc_se_ip: bad alloc\n");
+		return;
+	}
 	encrypted->set_iv(encrypted, iv);
 	encrypted->set_crypt_key(encrypted, &encrypted_pk_sesskey->key[0]);
 	__ops_encrypt_init(encrypted);
@@ -1028,8 +1062,8 @@
 	__ops_writer_push(output, encrypt_se_ip_writer, NULL,
 			encrypt_se_ip_destroyer, se_ip);
 	/* tidy up */
-	(void) free(encrypted_pk_sesskey);
-	(void) free(iv);
+	free(encrypted_pk_sesskey);
+	free(iv);
 }
 
 static unsigned 
@@ -1090,8 +1124,8 @@
 	encrypt_se_ip_t	*se_ip;
 
 	se_ip = __ops_writer_get_arg(writer);
-	(void) free(se_ip->crypt);
-	(void) free(se_ip);
+	free(se_ip->crypt);
+	free(se_ip);
 }
 
 unsigned 
@@ -1109,7 +1143,10 @@
 	size_t		 sz_buf;
 
 	sz_preamble = crypted->blocksize + 2;
-	preamble = calloc(1, sz_preamble);
+	if ((preamble = calloc(1, sz_preamble)) == NULL) {
+		(void) fprintf(stderr, "__ops_write_se_ip_pktset: bad alloc\n");
+		return 0;
+	}
 	sz_buf = sz_preamble + len + sz_mdc;
 
 	if (!__ops_write_ptag(output, OPS_PTAG_CT_SE_IP_DATA) ||
@@ -1123,7 +1160,7 @@
 	preamble[crypted->blocksize + 1] = preamble[crypted->blocksize - 1];
 
 	if (__ops_get_debug_level(__FILE__)) {
-		unsigned int    i = 0;
+		unsigned int    i;
 
 		fprintf(stderr, "\npreamble: ");
 		for (i = 0; i < sz_preamble; i++) {
@@ -1138,10 +1175,10 @@
 	__ops_write_mdc(hashed, mdcoutput);
 
 	if (__ops_get_debug_level(__FILE__)) {
-		unsigned int    i = 0;
+		unsigned int    i;
 		size_t          sz_plaintext = len;
 		size_t          sz_mdc2 = 1 + 1 + OPS_SHA1_HASH_SIZE;
-		unsigned char  *digest = NULL;
+		unsigned char  *digest;
 
 		(void) fprintf(stderr, "\nplaintext: ");
 		for (i = 0; i < sz_plaintext; i++) {
@@ -1161,7 +1198,7 @@
 	__ops_push_enc_crypt(output, crypted);
 	if (__ops_get_debug_level(__FILE__)) {
 		(void) fprintf(stderr,
-			"writing %" PRIsize "u + %d + %" PRIsize "u\n",
+			"writing %" PRIsize "u + %u + %" PRIsize "u\n",
 			sz_preamble, len, __ops_mem_len(mdc));
 	}
 	if (!__ops_write(output, preamble, sz_preamble) ||
@@ -1175,7 +1212,7 @@
 
 	/* cleanup  */
 	__ops_teardown_memory_write(mdcoutput, mdc);
-	(void) free(preamble);
+	free(preamble);
 
 	return 1;
 }
@@ -1210,7 +1247,7 @@
 static void 
 writer_fd_destroyer(__ops_writer_t *writer)
 {
-	(void) free(__ops_writer_get_arg(writer));
+	free(__ops_writer_get_arg(writer));
 }
 
 /**
@@ -1231,9 +1268,12 @@
 {
 	writer_fd_t	*writer;
 
-	writer = calloc(1, sizeof(*writer));
-	writer->fd = fd;
-	__ops_writer_set(output, fd_writer, NULL, writer_fd_destroyer, writer);
+	if ((writer = calloc(1, sizeof(*writer))) == NULL) {
+		(void) fprintf(stderr, "__ops_writer_set_fd: bad alloc\n");
+	} else {
+		writer->fd = fd;
+		__ops_writer_set(output, fd_writer, NULL, writer_fd_destroyer, writer);
+	}
 }
 
 static unsigned 
@@ -1313,7 +1353,7 @@
 	skey_checksum_t *sum;
 
 	sum = __ops_writer_get_arg(writer);
-	(void) free(sum);
+	free(sum);
 }
 
 /**
@@ -1327,15 +1367,18 @@
 	/* XXX: push a SHA-1 checksum writer (and change s2k to 254). */
 	skey_checksum_t *sum;
 
-	sum = calloc(1, sizeof(*sum));
-	/* configure the arg */
-	sum->hash_alg = seckey->hash_alg;
-	sum->hashed = seckey->checkhash;
-	/* init the hash */
-	__ops_hash_any(&sum->hash, sum->hash_alg);
-	sum->hash.init(&sum->hash);
-	__ops_writer_push(output, skey_checksum_writer,
-		skey_checksum_finaliser, skey_checksum_destroyer, sum);
+	if ((sum = calloc(1, sizeof(*sum))) == NULL) {
+		(void) fprintf(stderr, "__ops_push_checksum_writer: bad alloc\n");
+	} else {
+		/* configure the arg */
+		sum->hash_alg = seckey->hash_alg;
+		sum->hashed = seckey->checkhash;
+		/* init the hash */
+		__ops_hash_any(&sum->hash, sum->hash_alg);
+		sum->hash.init(&sum->hash);
+		__ops_writer_push(output, skey_checksum_writer,
+			skey_checksum_finaliser, skey_checksum_destroyer, sum);
+	}
 }
 
 /**************************************************************************/
@@ -1377,17 +1420,33 @@
 {
 	__ops_pk_sesskey_t	*encrypted_pk_sesskey;
 	const unsigned int	 bufsz = 1024;
-	str_enc_se_ip_t		*se_ip = calloc(1, sizeof(*se_ip));
+	str_enc_se_ip_t		*se_ip;
 	__ops_crypt_t		*encrypted;
-	unsigned char		*iv = NULL;
+	unsigned char		*iv;
 
+	if ((se_ip = calloc(1, sizeof(*se_ip))) == NULL) {
+		(void) fprintf(stderr,
+			"__ops_push_stream_enc_se_ip: bad alloc\n");
+		return;
+	}
 	encrypted_pk_sesskey = __ops_create_pk_sesskey(pubkey);
 	__ops_write_pk_sesskey(output, encrypted_pk_sesskey);
 
 	/* Setup the se_ip */
-	encrypted = calloc(1, sizeof(*encrypted));
+	if ((encrypted = calloc(1, sizeof(*encrypted))) == NULL) {
+		free(se_ip);
+		(void) fprintf(stderr,
+			"__ops_push_stream_enc_se_ip: bad alloc\n");
+		return;
+	}
 	__ops_crypt_any(encrypted, encrypted_pk_sesskey->symm_alg);
-	iv = calloc(1, encrypted->blocksize);
+	if ((iv = calloc(1, encrypted->blocksize)) == NULL) {
+		free(encrypted);
+		free(se_ip);
+		(void) fprintf(stderr,
+			"__ops_push_stream_enc_se_ip: bad alloc\n");
+		return;
+	}
 	encrypted->set_iv(encrypted, iv);
 	encrypted->set_crypt_key(encrypted, &encrypted_pk_sesskey->key[0]);
 	__ops_encrypt_init(encrypted);
@@ -1408,8 +1467,8 @@
 			str_enc_se_ip_finaliser,
 			str_enc_se_ip_destroyer, se_ip);
 	/* tidy up */
-	(void) free(encrypted_pk_sesskey);
-	(void) free(iv);
+	free(encrypted_pk_sesskey);
+	free(iv);
 }
 
 
@@ -1549,9 +1608,14 @@
 	blocksize = se_ip->crypt->blocksize;
 	sz_preamble = blocksize + 2;
 	sz_towrite = sz_preamble + 1 + len;
-	preamble = calloc(1, sz_preamble);
+	if ((preamble = calloc(1, sz_preamble)) == NULL) {
+		(void) fprintf(stderr,
+			"stream_write_se_ip_first: bad alloc\n");
+		return 0;
+	}
 	sz_pd = __ops_partial_data_len(sz_towrite);
 	if (sz_pd < 512) {
+		free(preamble);
 		(void) fprintf(stderr,
 			"stream_write_se_ip_first: bad sz_pd\n");
 		return 0;
@@ -1574,7 +1638,7 @@
 	sz_towrite -= sz_pd;
 	__ops_writer_pop(output);
 	stream_write_se_ip(output, data, sz_towrite, se_ip);
-	(void) free(preamble);
+	free(preamble);
 	return 1;
 }
 
@@ -1723,6 +1787,6 @@
 
 	se_ip->crypt->decrypt_finish(se_ip->crypt);
 
-	(void) free(se_ip->crypt);
-	(void) free(se_ip);
+	free(se_ip->crypt);
+	free(se_ip);
 }

Reply via email to