mirror of
git://git.gnupg.org/gnupg.git
synced 2025-07-02 22:46:30 +02:00
* keybox-defs.h: New BLOBTYPTE_EMPTY.
* keybox-dump.c (_keybox_dump_blob): Handle new type. * keybox-file.c (_keybox_read_blob): Skip over empty blobs. Store the file offset. * keybox-blob.c (_keybox_new_blob): Add new arg OFF. (_keybox_get_blob_fileoffset): New. * keybox-update.c (keybox_delete): Implemented.
This commit is contained in:
parent
bbf580e702
commit
508ce100c9
6 changed files with 101 additions and 16 deletions
|
@ -32,38 +32,54 @@ _keybox_read_blob (KEYBOXBLOB *r_blob, FILE *fp)
|
|||
{
|
||||
char *image;
|
||||
size_t imagelen = 0;
|
||||
int c1, c2, c3, c4;
|
||||
int c1, c2, c3, c4, type;
|
||||
int rc;
|
||||
off_t off;
|
||||
|
||||
again:
|
||||
*r_blob = NULL;
|
||||
off = ftello (fp);
|
||||
if (off == (off_t)-1)
|
||||
return KEYBOX_Read_Error;
|
||||
|
||||
if ((c1 = getc (fp)) == EOF
|
||||
|| (c2 = getc (fp)) == EOF
|
||||
|| (c3 = getc (fp)) == EOF
|
||||
|| (c4 = getc (fp)) == EOF ) {
|
||||
if ( c1 == EOF && !ferror (fp) )
|
||||
return -1; /* eof */
|
||||
return KEYBOX_Read_Error;
|
||||
}
|
||||
|| (c4 = getc (fp)) == EOF
|
||||
|| (type = getc (fp)) == EOF)
|
||||
{
|
||||
if ( c1 == EOF && !ferror (fp) )
|
||||
return -1; /* eof */
|
||||
return KEYBOX_Read_Error;
|
||||
}
|
||||
|
||||
imagelen = (c1 << 24) | (c2 << 16) | (c3 << 8 ) | c4;
|
||||
if (imagelen > 500000) /* sanity check */
|
||||
return KEYBOX_Blob_Too_Large;
|
||||
|
||||
if (imagelen < 4)
|
||||
if (imagelen < 5)
|
||||
return KEYBOX_Blob_Too_Short;
|
||||
|
||||
|
||||
if (!type)
|
||||
{
|
||||
/* special treatment for empty blobs. */
|
||||
if (fseek (fp, imagelen-5, SEEK_CUR))
|
||||
return KEYBOX_Read_Error;
|
||||
goto again;
|
||||
}
|
||||
|
||||
image = xtrymalloc (imagelen);
|
||||
if (!image)
|
||||
return KEYBOX_Out_Of_Core;
|
||||
|
||||
image[0] = c1; image[1] = c2; image[2] = c3; image[3] = c4;
|
||||
if (fread (image+4, imagelen-4, 1, fp) != 1)
|
||||
image[0] = c1; image[1] = c2; image[2] = c3; image[3] = c4; image[4] = type;
|
||||
if (fread (image+5, imagelen-5, 1, fp) != 1)
|
||||
{
|
||||
xfree (image);
|
||||
return KEYBOX_Read_Error;
|
||||
}
|
||||
|
||||
rc = r_blob? _keybox_new_blob (r_blob, image, imagelen) : 0;
|
||||
rc = r_blob? _keybox_new_blob (r_blob, image, imagelen, off) : 0;
|
||||
if (rc || !r_blob)
|
||||
xfree (image);
|
||||
return rc;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue