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 More Flexelint clean...
details: https://anonhg.NetBSD.org/src/rev/86a93815732c
branches: trunk
changeset: 747940:86a93815732c
user: agc <agc%NetBSD.org@localhost>
date: Tue Oct 06 05:54:24 2009 +0000
description:
More Flexelint cleanup from issues pointed out by phk - thanks! - just easy
low-hanging fruit for now.
diffstat:
crypto/external/bsd/netpgp/dist/src/lib/packet-parse.c | 158 +++++++++-------
crypto/external/bsd/netpgp/dist/src/lib/packet.h | 1 +
2 files changed, 90 insertions(+), 69 deletions(-)
diffs (truncated from 569 to 300 lines):
diff -r f9555d40582c -r 86a93815732c crypto/external/bsd/netpgp/dist/src/lib/packet-parse.c
--- a/crypto/external/bsd/netpgp/dist/src/lib/packet-parse.c Tue Oct 06 05:03:58 2009 +0000
+++ b/crypto/external/bsd/netpgp/dist/src/lib/packet-parse.c Tue Oct 06 05:54:24 2009 +0000
@@ -58,7 +58,7 @@
#if defined(__NetBSD__)
__COPYRIGHT("@(#) Copyright (c) 2009 The NetBSD Foundation, Inc. All rights reserved.");
-__RCSID("$NetBSD: packet-parse.c,v 1.23 2009/10/04 21:55:55 agc Exp $");
+__RCSID("$NetBSD: packet-parse.c,v 1.24 2009/10/06 05:54:24 agc Exp $");
#endif
#ifdef HAVE_OPENSSL_CAST_H
@@ -73,8 +73,6 @@
#include <unistd.h>
#endif
-#include <errno.h>
-
#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif
@@ -156,7 +154,7 @@
read_unsig_str(unsigned char **str, __ops_region_t *subregion,
__ops_stream_t *stream)
{
- size_t len = 0;
+ size_t len;
len = subregion->length - subregion->readc;
if ((*str = calloc(1, len + 1)) == NULL) {
@@ -242,7 +240,7 @@
if (r == 0) {
break;
}
- n += r;
+ n += (unsigned)r;
}
if (n == 0) {
@@ -254,9 +252,16 @@
return 0;
}
if (readinfo->alength + n > readinfo->asize) {
- readinfo->asize = readinfo->asize * 2 + n;
- readinfo->accumulated = realloc(readinfo->accumulated,
- readinfo->asize);
+ unsigned char *temp;
+
+ readinfo->asize = (readinfo->asize * 2) + n;
+ temp = realloc(readinfo->accumulated, readinfo->asize);
+ if (temp == NULL) {
+ (void) fprintf(stderr,
+ "sub_base_read: bad alloc\n");
+ return 0;
+ }
+ readinfo->accumulated = temp;
}
if (readinfo->asize < readinfo->alength + n) {
(void) fprintf(stderr, "sub_base_read: bad realloc\n");
@@ -313,7 +318,7 @@
*last_read = r;
return t;
}
- t += r;
+ t += (size_t)r;
}
*last_read = r;
@@ -592,7 +597,7 @@
{
unsigned char c;
time_t mytime = 0;
- int i = 0;
+ int i;
/*
* Cannot assume that time_t is 4 octets long -
@@ -645,10 +650,10 @@
* the buffer is NETPGP_BUFSIZ bytes. */
unsigned length;
unsigned nonzero;
- unsigned ret;
+ unsigned ret;
stream->reading_mpi_len = 1;
- ret = limread_scalar(&length, 2, region, stream);
+ ret = (unsigned)limread_scalar(&length, 2, region, stream);
stream->reading_mpi_len = 0;
if (!ret)
@@ -779,7 +784,7 @@
static void
data_free(__ops_data_t *data)
{
- (void) free(data->contents);
+ free(data->contents);
data->contents = NULL;
data->len = 0;
}
@@ -791,7 +796,7 @@
static void
string_free(char **str)
{
- (void) free(*str);
+ free(*str);
*str = NULL;
}
@@ -803,7 +808,7 @@
void
__ops_subpacket_free(__ops_subpacket_t *packet)
{
- (void) free(packet->raw);
+ free(packet->raw);
packet->raw = NULL;
}
@@ -817,10 +822,10 @@
unsigned n;
for (n = 0; n < headers->headerc; ++n) {
- (void) free(headers->headers[n].key);
- (void) free(headers->headers[n].value);
+ free(headers->headers[n].key);
+ free(headers->headers[n].value);
}
- (void) free(headers->headers);
+ free(headers->headers);
headers->headers = NULL;
}
@@ -831,7 +836,7 @@
static void
cleartext_trailer_free(__ops_cleartext_trailer_t *trailer)
{
- (void) free(trailer->hash);
+ free(trailer->hash);
trailer->hash = NULL;
}
@@ -843,7 +848,7 @@
__ops_cmd_get_passphrase_free(__ops_seckey_passphrase_t *skp)
{
if (skp->passphrase && *skp->passphrase) {
- (void) free(*skp->passphrase);
+ free(*skp->passphrase);
*skp->passphrase = NULL;
}
}
@@ -1282,7 +1287,7 @@
free_BN(&p->key.elgamal.y);
break;
- case 0:
+ case OPS_PKA_NOTHING:
/* nothing to free */
break;
@@ -1305,12 +1310,16 @@
(void) fprintf(stderr, "parse_pubkey_data: bad length\n");
return 0;
}
-
if (!limread(&c, 1, region, stream)) {
return 0;
}
- key->version = c;
- if (key->version < 2 || key->version > 4) {
+ key->version = (__ops_version_t)c;
+ switch (key->version) {
+ case OPS_V2:
+ case OPS_V3:
+ case OPS_V4:
+ break;
+ default:
OPS_ERROR_1(&stream->errors, OPS_E_PROTO_BAD_PUBLIC_KEY_VRSN,
"Bad public key version (0x%02x)", key->version);
return 0;
@@ -1458,7 +1467,7 @@
void
__ops_userid_free(__ops_userid_t *id)
{
- (void) free(id->userid);
+ free(id->userid);
id->userid = NULL;
}
@@ -1492,8 +1501,10 @@
return 0;
}
- /* XXX should we not like check malloc's return value? */
- pkt.u.userid.userid = calloc(1, region->length + 1);
+ if ((pkt.u.userid.userid = calloc(1, region->length + 1)) == NULL) {
+ (void) fprintf(stderr, "parse_userid: bad alloc\n");
+ return 0;
+ }
if (region->length &&
!limread(pkt.u.userid.userid, region->length, region,
@@ -1539,7 +1550,7 @@
__ops_stream_t *stream)
{
__ops_packet_t pkt;
- unsigned char c = 0x0;
+ unsigned char c = 0x0;
/* clear signature */
(void) memset(&pkt.u.sig, 0x0, sizeof(pkt.u.sig));
@@ -1557,7 +1568,7 @@
if (!limread(&c, 1, region, stream)) {
return 0;
}
- pkt.u.sig.info.type = c;
+ pkt.u.sig.info.type = (__ops_sig_type_t)c;
/* XXX: check signature type */
if (!limited_read_time(&pkt.u.sig.info.birthtime, region, stream)) {
@@ -1574,13 +1585,13 @@
if (!limread(&c, 1, region, stream)) {
return 0;
}
- pkt.u.sig.info.key_alg = c;
+ pkt.u.sig.info.key_alg = (__ops_pubkey_alg_t)c;
/* XXX: check algorithm */
if (!limread(&c, 1, region, stream)) {
return 0;
}
- pkt.u.sig.info.hash_alg = c;
+ pkt.u.sig.info.hash_alg = (__ops_hash_alg_t)c;
/* XXX: check algorithm */
if (!limread(pkt.u.sig.hash2, 2, region, stream)) {
@@ -1681,7 +1692,7 @@
t7 = 1 << (c & 7);
pkt.critical = (unsigned)c >> 7;
- pkt.tag = OPS_PTAG_SIG_SUBPKT_BASE + (c & 0x7f);
+ pkt.tag = (__ops_content_tag_t)(OPS_PTAG_SIG_SUBPKT_BASE + (c & 0x7f));
/* Application wants it delivered raw */
if (stream->ss_raw[t8] & t7) {
@@ -2020,7 +2031,7 @@
if (!limread(&c, 1, region, stream)) {
return 0;
}
- pkt.u.sig.info.type = c;
+ pkt.u.sig.info.type = (__ops_sig_type_t)c;
if (__ops_get_debug_level(__FILE__)) {
fprintf(stderr, "signature type=%d (%s)\n",
pkt.u.sig.info.type,
@@ -2031,7 +2042,7 @@
if (!limread(&c, 1, region, stream)) {
return 0;
}
- pkt.u.sig.info.key_alg = c;
+ pkt.u.sig.info.key_alg = (__ops_pubkey_alg_t)c;
/* XXX: check algorithm */
if (__ops_get_debug_level(__FILE__)) {
(void) fprintf(stderr, "key_alg=%d (%s)\n",
@@ -2041,7 +2052,7 @@
if (!limread(&c, 1, region, stream)) {
return 0;
}
- pkt.u.sig.info.hash_alg = c;
+ pkt.u.sig.info.hash_alg = (__ops_hash_alg_t)c;
/* XXX: check algorithm */
if (__ops_get_debug_level(__FILE__)) {
fprintf(stderr, "hash_alg=%d %s\n",
@@ -2059,7 +2070,7 @@
/* copy hashed subpackets */
if (pkt.u.sig.info.v4_hashed) {
- (void) free(pkt.u.sig.info.v4_hashed);
+ free(pkt.u.sig.info.v4_hashed);
}
pkt.u.sig.info.v4_hashed = calloc(1, pkt.u.sig.info.v4_hashlen);
@@ -2195,13 +2206,13 @@
parse_compressed(__ops_region_t *region, __ops_stream_t *stream)
{
__ops_packet_t pkt;
- unsigned char c = 0x0;
+ unsigned char c = 0x0;
if (!limread(&c, 1, region, stream)) {
return 0;
}
- pkt.u.compressed.type = c;
+ pkt.u.compressed.type = (__ops_compression_type_t)c;
CALLBACK(OPS_PTAG_CT_COMPRESSED, &stream->cbinfo, &pkt);
@@ -2252,17 +2263,17 @@
if (!limread(&c, 1, region, stream)) {
return 0;
}
- pkt.u.one_pass_sig.sig_type = c;
Home |
Main Index |
Thread Index |
Old Index