summaryrefslogtreecommitdiff
path: root/lib/opencdk
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@gnutls.org>2012-09-22 01:45:33 +0200
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2012-09-22 09:56:25 +0200
commit6aca5dd7b7adb29d94114cbc0d575cb83a181ddd (patch)
treec7b8bfcfad7619ea9a8c86b2203a6361620736c8 /lib/opencdk
parentf06c535863b315535961ac9aa52a9d51cd50766a (diff)
downloadgnutls-6aca5dd7b7adb29d94114cbc0d575cb83a181ddd.tar.gz
several cleanups
Diffstat (limited to 'lib/opencdk')
-rw-r--r--lib/opencdk/armor.c5
-rw-r--r--lib/opencdk/keydb.c4
-rw-r--r--lib/opencdk/literal.c1
-rw-r--r--lib/opencdk/stream.c2
-rw-r--r--lib/opencdk/write-packet.c42
5 files changed, 27 insertions, 27 deletions
diff --git a/lib/opencdk/armor.c b/lib/opencdk/armor.c
index fbfab152e7..1d2a645201 100644
--- a/lib/opencdk/armor.c
+++ b/lib/opencdk/armor.c
@@ -526,10 +526,9 @@ cdk_armor_encode_buffer (const byte * inbuf, size_t inlen,
return 0;
}
- pos = 0;
memset (outbuf, 0, outlen);
- memcpy (outbuf + pos, "-----", 5);
- pos += 5;
+ memcpy (outbuf, "-----", 5);
+ pos = 5;
memcpy (outbuf + pos, head, strlen (head));
pos += strlen (head);
memcpy (outbuf + pos, "-----", 5);
diff --git a/lib/opencdk/keydb.c b/lib/opencdk/keydb.c
index b74feda2dc..646904dbe3 100644
--- a/lib/opencdk/keydb.c
+++ b/lib/opencdk/keydb.c
@@ -1198,7 +1198,7 @@ _cdk_keydb_get_sk_byusage (cdk_keydb_hd_t hd, const char *name,
return CDK_Unusable_Key;
}
node = find_selfsig_node (knode, pk_node->pkt->pkt.secret_key->pk);
- if (sk->pk->uid && node)
+ if (sk && sk->pk && sk->pk->uid && node)
_cdk_copy_signature (&sk->pk->uid->selfsig, node->pkt->pkt.signature);
/* We only release the outer packet. */
@@ -1275,7 +1275,7 @@ _cdk_keydb_get_pk_byusage (cdk_keydb_hd_t hd, const char *name,
return CDK_Unusable_Key;
}
node = find_selfsig_node (knode, pk_node->pkt->pkt.public_key);
- if (pk->uid && node)
+ if (pk && pk->uid && node)
_cdk_copy_signature (&pk->uid->selfsig, node->pkt->pkt.signature);
cdk_kbnode_release (knode);
diff --git a/lib/opencdk/literal.c b/lib/opencdk/literal.c
index eb16188f5a..7b0ec0da28 100644
--- a/lib/opencdk/literal.c
+++ b/lib/opencdk/literal.c
@@ -215,7 +215,6 @@ literal_encode (void *data, FILE * in, FILE * out)
pt->buf = si;
pkt->old_ctb = 1;
pkt->pkttype = CDK_PKT_LITERAL;
- pkt->pkt.literal = pt;
rc = _cdk_pkt_write_fp (out, pkt);
cdk_pkt_release (pkt);
diff --git a/lib/opencdk/stream.c b/lib/opencdk/stream.c
index 7c620959c9..bfc96abdb4 100644
--- a/lib/opencdk/stream.c
+++ b/lib/opencdk/stream.c
@@ -1042,7 +1042,7 @@ cdk_stream_write (cdk_stream_t s, const void *buf, size_t count)
return EOF;
}
- if (!buf && !count)
+ if (!buf || !count)
return stream_flush (s);
if (s->cache.on)
diff --git a/lib/opencdk/write-packet.c b/lib/opencdk/write-packet.c
index 0937c77927..77b9db1409 100644
--- a/lib/opencdk/write-packet.c
+++ b/lib/opencdk/write-packet.c
@@ -146,9 +146,9 @@ pkt_encode_len (cdk_stream_t out, size_t pktlen)
{
cdk_error_t rc;
- assert (out);
+ if (!out)
+ return CDK_Inv_Value;
- rc = 0;
if (!pktlen)
{
/* Block mode, partial bodies, with 'DEF_BLOCKSIZE' from main.h */
@@ -179,7 +179,8 @@ write_head_new (cdk_stream_t out, size_t size, int type)
{
cdk_error_t rc;
- assert (out);
+ if (!out)
+ return CDK_Inv_Value;
if (type < 0 || type > 63)
return CDK_Inv_Packet;
@@ -196,7 +197,8 @@ write_head_old (cdk_stream_t out, size_t size, int type)
cdk_error_t rc;
int ctb;
- assert (out);
+ if (!out)
+ return CDK_Inv_Value;
if (type < 0 || type > 16)
return CDK_Inv_Packet;
@@ -257,8 +259,8 @@ write_pubkey_enc (cdk_stream_t out, cdk_pkt_pubkey_enc_t pke, int old_ctb)
size_t size;
int rc, nenc;
- assert (out);
- assert (pke);
+ if (!out || !pke)
+ return CDK_Inv_Value;
if (pke->version < 2 || pke->version > 3)
return CDK_Inv_Packet;
@@ -292,8 +294,8 @@ write_mdc (cdk_stream_t out, cdk_pkt_mdc_t mdc)
{
cdk_error_t rc;
- assert (mdc);
- assert (out);
+ if (!out || !mdc)
+ return CDK_Inv_Value;
if (DEBUG_PKT)
_gnutls_write_log ("write_mdc:\n");
@@ -363,8 +365,8 @@ write_signature (cdk_stream_t out, cdk_pkt_signature_t sig, int old_ctb)
size_t nbytes, size, nsig;
cdk_error_t rc;
- assert (out);
- assert (sig);
+ if (!out || !sig)
+ return CDK_Inv_Value;
if (!KEY_CAN_SIGN (sig->pubkey_algo))
return CDK_Inv_Algo;
@@ -429,8 +431,8 @@ write_public_key (cdk_stream_t out, cdk_pkt_pubkey_t pk,
size_t npkey = 0, size = 6;
cdk_error_t rc;
- assert (out);
- assert (pk);
+ if (!out || !pk)
+ return CDK_Inv_Value;
if (pk->version < 2 || pk->version > 4)
return CDK_Inv_Packet;
@@ -506,8 +508,8 @@ write_secret_key (cdk_stream_t out, cdk_pkt_seckey_t sk,
int pkttype, s2k_mode;
cdk_error_t rc;
- assert (out);
- assert (sk);
+ if (!out || !sk)
+ return CDK_Inv_Value;
if (!sk->pk)
return CDK_Inv_Value;
@@ -626,8 +628,8 @@ write_compressed (cdk_stream_t out, cdk_pkt_compressed_t cd)
{
cdk_error_t rc;
- assert (out);
- assert (cd);
+ if (!out || !cd)
+ return CDK_Inv_Value;
if (DEBUG_PKT)
_gnutls_write_log ("packet: write_compressed\n");
@@ -647,8 +649,8 @@ write_literal (cdk_stream_t out, cdk_pkt_literal_t pt, int old_ctb)
size_t size;
cdk_error_t rc;
- assert (out);
- assert (pt);
+ if (!out || !pt)
+ return CDK_Inv_Value;
/* We consider a packet without a body as an invalid packet.
At least one octet must be present. */
@@ -694,8 +696,8 @@ write_onepass_sig (cdk_stream_t out, cdk_pkt_onepass_sig_t sig)
{
cdk_error_t rc;
- assert (out);
- assert (sig);
+ if (!out || !sig)
+ return CDK_Inv_Value;
if (sig->version != 3)
return CDK_Inv_Packet;