Browse Source

Fixes in pgp_keydata_dup, added more DYNARRAY handling macros, plus some strange WTF stuff commented out in add key to pubring

master
Edouard Tisserant 7 years ago
parent
commit
1176387389
2 changed files with 28 additions and 8 deletions
  1. +13
    -8
      dist/src/lib/keyring.c
  2. +15
    -0
      dist/src/lib/packet.h

+ 13
- 8
dist/src/lib/keyring.c View File

@ -125,16 +125,14 @@ pgp_key_free(pgp_key_t *keydata)
for (n = 0; n < keydata->uidc; ++n) {
pgp_userid_free(&keydata->uids[n]);
}
free(keydata->uids);
keydata->uids = NULL;
keydata->uidc = 0;
FREE_ARRAY(keydata, uid);
for (n = 0; n < keydata->packetc; ++n) {
pgp_subpacket_free(&keydata->packets[n]);
}
free(keydata->packets);
keydata->packets = NULL;
keydata->packetc = 0;
FREE_ARRAY(keydata, packet);
/* XXX subsigs revokes ? */
@ -169,8 +167,15 @@ pgp_keydata_dup(pgp_key_t *dst, pgp_key_t *src, unsigned make_public)
int res = 0;
unsigned pktcpyof = 0;
/* XXX quite hazardous copy */
memcpy(dst, src, sizeof(pgp_key_t));
/* reset DYNARRAYs */
INIT_ARRAY(dst, uid);
INIT_ARRAY(dst, packet);
INIT_ARRAY(dst, subsig);
INIT_ARRAY(dst, revoke);
if (src->type == PGP_PTAG_CT_PUBLIC_KEY) {
res = pgp_pubkey_dup(&dst->key.pubkey, &src->key.pubkey);
} else if (make_public && (
@ -1289,13 +1294,13 @@ pgp_add_to_pubring(pgp_keyring_t *keyring, const pgp_pubkey_t *pubkey, pgp_conte
case PGP_PTAG_CT_PUBLIC_KEY:
EXPAND_ARRAY(keyring, key);
key = &keyring->keys[keyring->keyc++];
duration = key->key.pubkey.duration;
/* WTF? duration = key->key.pubkey.duration; */
(void) memset(key, 0x0, sizeof(*key));
key->type = tag;
pgp_keyid(key->sigid, PGP_KEY_ID_SIZE, pubkey, keyring->hashtype);
pgp_fingerprint(&key->sigfingerprint, pubkey, keyring->hashtype);
key->key.pubkey = *pubkey;
key->key.pubkey.duration = duration;
/* WTF? key->key.pubkey.duration = duration; */
return 1;
case PGP_PTAG_CT_PUBLIC_SUBKEY:
/* subkey is not the first */


+ 15
- 0
dist/src/lib/packet.h View File

@ -921,6 +921,21 @@ int pgp_print_packet(pgp_printstate_t *, const pgp_packet_t *);
} \
} while(/*CONSTCOND*/0)
#define FREE_ARRAY(str, arr) do { \
if (str->arr##s) { \
free(str->arr##s); \
str->arr##s = NULL; \
str->arr##vsize = 0; \
str->arr##c = 0; \
} \
} while(/*CONSTCOND*/0)
#define INIT_ARRAY(str, arr) do { \
str->arr##s = NULL; \
str->arr##vsize = 0; \
str->arr##c = 0; \
} while(/*CONSTCOND*/0)
/** pgp_keydata_key_t
*/
typedef union {


Loading…
Cancel
Save