Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/crypto/external/bsd/netpgp/dist/src/lib Clean up some Flexel...
details: https://anonhg.NetBSD.org/src/rev/5f6451432b8c
branches: trunk
changeset: 747959:5f6451432b8c
user: agc <agc%NetBSD.org@localhost>
date: Wed Oct 07 04:18:47 2009 +0000
description:
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.
diffstat:
crypto/external/bsd/netpgp/dist/src/lib/netpgp.c | 59 +++-
crypto/external/bsd/netpgp/dist/src/lib/packet-print.c | 43 +-
crypto/external/bsd/netpgp/dist/src/lib/packet-show.c | 88 +++---
crypto/external/bsd/netpgp/dist/src/lib/reader.c | 158 ++++++-----
crypto/external/bsd/netpgp/dist/src/lib/signature.c | 14 +-
crypto/external/bsd/netpgp/dist/src/lib/symmetric.c | 20 +-
crypto/external/bsd/netpgp/dist/src/lib/validate.c | 101 +++++--
crypto/external/bsd/netpgp/dist/src/lib/writer.c | 210 +++++++++++-----
8 files changed, 420 insertions(+), 273 deletions(-)
diffs (truncated from 1769 to 300 lines):
diff -r cc547b34ccb1 -r 5f6451432b8c crypto/external/bsd/netpgp/dist/src/lib/netpgp.c
--- a/crypto/external/bsd/netpgp/dist/src/lib/netpgp.c Wed Oct 07 01:31:41 2009 +0000
+++ b/crypto/external/bsd/netpgp/dist/src/lib/netpgp.c Wed Oct 07 04:18:47 2009 +0000
@@ -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]) {
diff -r cc547b34ccb1 -r 5f6451432b8c crypto/external/bsd/netpgp/dist/src/lib/packet-print.c
--- a/crypto/external/bsd/netpgp/dist/src/lib/packet-print.c Wed Oct 07 01:31:41 2009 +0000
+++ b/crypto/external/bsd/netpgp/dist/src/lib/packet-print.c Wed Oct 07 04:18:47 2009 +0000
@@ -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);
diff -r cc547b34ccb1 -r 5f6451432b8c crypto/external/bsd/netpgp/dist/src/lib/packet-show.c
--- a/crypto/external/bsd/netpgp/dist/src/lib/packet-show.c Wed Oct 07 01:31:41 2009 +0000
+++ b/crypto/external/bsd/netpgp/dist/src/lib/packet-show.c Wed Oct 07 04:18:47 2009 +0000
@@ -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
Home |
Main Index |
Thread Index |
Old Index