kbx: Minor cleanup for the previous fix.

* kbx/keybox-search.c (blob_get_keyid): Rename to
blob_get_first_keyid. Check number of keys and remove blob type check.
--

There is no need to check the blob type.  We already know that it is a
key blob type and keyids are used for X.509 and OpenPGP.  Also added
check for number of keys because the other parser functions do it as
well.

Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
Werner Koch 2015-01-19 14:58:06 +01:00
parent c5956592c1
commit 7be1b7d801
1 changed files with 7 additions and 7 deletions

View File

@ -79,21 +79,21 @@ blob_get_blob_flags (KEYBOXBLOB blob)
}
/* Return the first keyid from the blob. Returns true if
available. */
static int
blob_get_keyid (KEYBOXBLOB blob, u32 *kid)
blob_get_first_keyid (KEYBOXBLOB blob, u32 *kid)
{
const unsigned char *buffer;
size_t length, keyinfolen;
size_t length, nkeys, keyinfolen;
buffer = _keybox_get_blob_image (blob, &length);
if (length < 48)
return 0; /* blob too short */
if (buffer[4] != KEYBOX_BLOBTYPE_PGP)
return 0; /* don't know what to do with X.509 blobs */
nkeys = get16 (buffer + 16);
keyinfolen = get16 (buffer + 18);
if (keyinfolen < 28)
if (!nkeys || keyinfolen < 28)
return 0; /* invalid blob */
kid[0] = get32 (buffer + 32);
@ -994,7 +994,7 @@ keybox_search (KEYBOX_HANDLE hd, KEYBOX_SEARCH_DESC *desc, size_t ndesc,
u32 kid[2];
if (desc[n].skipfnc
&& blob_get_keyid (blob, kid)
&& blob_get_first_keyid (blob, kid)
&& desc[n].skipfnc (desc[n].skipfncvalue, kid, NULL))
break;
}