Allow NULL for free_public_key.

This commit is contained in:
Werner Koch 2011-09-20 19:24:52 +02:00
parent 850f09b2e3
commit 6cf8890dc1
8 changed files with 36 additions and 34 deletions

View File

@ -1,3 +1,14 @@
2011-09-20 Werner Koch <wk@g10code.com>
* free-packet.c (free_public_key): Allow a NULL argument.
* keyedit.c (keyedit_passwd): No more need to check that PK is NULL.
(menu_addrevoker): Ditto.
* passphrase.c (passphrase_get, passphrase_to_dek_ext): Ditto.
* skclist.c (release_sk_list): Ditto.
* revoke.c (gen_desig_revoke): Ditto.
* pubkey-enc.c (get_session_key): Ditto.
* pkclist.c (build_pk_list): Ditto.
2011-09-20 Jim Meyering <meyering@redhat.com>
avoid use of freed pointer

View File

@ -120,11 +120,16 @@ release_public_key_parts (PKT_public_key *pk)
}
/* Free an allocated public key structure including all parts.
Passing NULL is allowed. */
void
free_public_key (PKT_public_key *pk)
{
release_public_key_parts (pk);
xfree(pk);
if (pk)
{
release_public_key_parts (pk);
xfree(pk);
}
}

View File

@ -2253,8 +2253,7 @@ keyedit_passwd (ctrl_t ctrl, const char *username)
leave:
release_kbnode (keyblock);
if (pk)
free_public_key (pk);
free_public_key (pk);
if (err)
{
log_info ("error changing the passphrase for `%s': %s\n",
@ -3327,9 +3326,7 @@ menu_addrevoker (ctrl_t ctrl, kbnode_t pub_keyblock, int sensitive)
{
char *answer;
if (revoker_pk)
free_public_key (revoker_pk);
free_public_key (revoker_pk);
revoker_pk = xmalloc_clear (sizeof (*revoker_pk));
tty_printf ("\n");
@ -3453,8 +3450,7 @@ menu_addrevoker (ctrl_t ctrl, kbnode_t pub_keyblock, int sensitive)
fail:
if (sig)
free_seckey_enc (sig);
if (revoker_pk)
free_public_key (revoker_pk);
free_public_key (revoker_pk);
return 0;
}

View File

@ -235,8 +235,7 @@ passphrase_get ( u32 *keyid, int mode, const char *cacheid, int repeat,
memset (fpr, 0, MAX_FINGERPRINT_LEN );
if( keyid && get_pubkey( pk, keyid ) )
{
if (pk)
free_public_key( pk );
free_public_key (pk);
pk = NULL; /* oops: no key for some reason */
}
@ -344,8 +343,7 @@ passphrase_get ( u32 *keyid, int mode, const char *cacheid, int repeat,
write_status_errcode ("get_passphrase", rc);
}
if (pk)
free_public_key( pk );
free_public_key (pk);
if (rc)
{
xfree (pw);
@ -531,8 +529,7 @@ passphrase_to_dek_ext (u32 *keyid, int pubkey_algo,
}
tty_printf("\n");
if (pk)
free_public_key( pk );
free_public_key (pk);
}
if ( next_pw )

View File

@ -1064,8 +1064,7 @@ build_pk_list (ctrl_t ctrl,
continue;
/* Get and check key for the current name. */
if (pk)
free_public_key (pk);
free_public_key (pk);
pk = xmalloc_clear( sizeof *pk );
pk->req_usage = use;
rc = get_pubkey_byname (ctrl, NULL, pk, answer, NULL, NULL, 0, 0 );
@ -1078,7 +1077,8 @@ build_pk_list (ctrl_t ctrl,
/* No validation for a default recipient. */
if (!key_present_in_pk_list(pk_list, pk))
{
free_public_key (pk); pk = NULL;
free_public_key (pk);
pk = NULL;
log_info (_("skipped: public key "
"already set as default recipient\n") );
}
@ -1108,7 +1108,8 @@ build_pk_list (ctrl_t ctrl,
* present in the list */
if (!key_present_in_pk_list(pk_list, pk))
{
free_public_key(pk); pk = NULL;
free_public_key (pk);
pk = NULL;
log_info(_("skipped: public key already set\n") );
}
else

View File

@ -97,8 +97,7 @@ get_session_key (PKT_pubkey_enc * k, DEK * dek)
for (;;)
{
if (sk)
free_public_key (sk);
free_public_key (sk);
sk = xmalloc_clear (sizeof *sk);
rc = enum_secret_keys (&enum_context, sk);
if (rc)
@ -127,8 +126,7 @@ get_session_key (PKT_pubkey_enc * k, DEK * dek)
}
leave:
if (sk)
free_public_key (sk);
free_public_key (sk);
return rc;
}

View File

@ -262,11 +262,8 @@ gen_desig_revoke( const char *uname, strlist_t locusr )
{
SK_LIST list;
if (pk2)
{
free_public_key (pk2);
pk2 = NULL;
}
free_public_key (pk2);
pk2 = NULL;
if(sk_list)
{
@ -417,10 +414,8 @@ gen_desig_revoke( const char *uname, strlist_t locusr )
log_error(_("no revocation keys found for \"%s\"\n"),uname);
leave:
if( pk )
free_public_key( pk );
if (pk2)
free_public_key (pk2);
free_public_key (pk);
free_public_key (pk2);
if( sig )
free_seckey_enc( sig );

View File

@ -51,8 +51,7 @@ release_sk_list (SK_LIST sk_list)
for (; sk_list; sk_list = sk_rover)
{
sk_rover = sk_list->next;
if (sk_list->pk)
free_public_key (sk_list->pk);
free_public_key (sk_list->pk);
xfree (sk_list);
}
}