diff options
author | Werner Koch <wk@gnupg.org> | 2008-05-06 16:03:36 +0200 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2008-05-06 16:03:36 +0200 |
commit | 4254e90426a97afaed1af3f4caa01cc2f4021fb6 (patch) | |
tree | 82e0123ba381605484c332038504dae8e967b2e7 /kbx/keybox-file.c | |
parent | add gpg-zip man page. (diff) | |
download | gnupg2-4254e90426a97afaed1af3f4caa01cc2f4021fb6.tar.xz gnupg2-4254e90426a97afaed1af3f4caa01cc2f4021fb6.zip |
Fixed bug#907.
Fixed a segv in keybox and made it more robust.
Diffstat (limited to 'kbx/keybox-file.c')
-rw-r--r-- | kbx/keybox-file.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/kbx/keybox-file.c b/kbx/keybox-file.c index 7a40e964b..c10aa1681 100644 --- a/kbx/keybox-file.c +++ b/kbx/keybox-file.c @@ -58,7 +58,7 @@ _keybox_read_blob2 (KEYBOXBLOB *r_blob, FILE *fp, int *skipped_deleted) *r_blob = NULL; off = ftello (fp); if (off == (off_t)-1) - return gpg_error (gpg_err_code_from_errno (errno)); + return gpg_error_from_syserror (); if ((c1 = getc (fp)) == EOF || (c2 = getc (fp)) == EOF @@ -68,7 +68,9 @@ _keybox_read_blob2 (KEYBOXBLOB *r_blob, FILE *fp, int *skipped_deleted) { if ( c1 == EOF && !ferror (fp) ) return -1; /* eof */ - return gpg_error (gpg_err_code_from_errno (errno)); + if (!ferror (fp)) + return gpg_error (GPG_ERR_TOO_SHORT); + return gpg_error_from_syserror (); } imagelen = (c1 << 24) | (c2 << 16) | (c3 << 8 ) | c4; @@ -82,26 +84,26 @@ _keybox_read_blob2 (KEYBOXBLOB *r_blob, FILE *fp, int *skipped_deleted) { /* Special treatment for empty blobs. */ if (fseek (fp, imagelen-5, SEEK_CUR)) - return gpg_error (gpg_err_code_from_errno (errno)); + return gpg_error_from_syserror (); *skipped_deleted = 1; goto again; } image = xtrymalloc (imagelen); if (!image) - return gpg_error (gpg_err_code_from_errno (errno)); + return gpg_error_from_syserror (); image[0] = c1; image[1] = c2; image[2] = c3; image[3] = c4; image[4] = type; if (fread (image+5, imagelen-5, 1, fp) != 1) { - gpg_error_t tmperr = gpg_error (gpg_err_code_from_errno (errno)); + gpg_error_t tmperr = gpg_error_from_syserror (); xfree (image); return tmperr; } rc = r_blob? _keybox_new_blob (r_blob, image, imagelen, off) : 0; if (rc || !r_blob) - xfree (image); + xfree (image); return rc; } @@ -122,7 +124,7 @@ _keybox_write_blob (KEYBOXBLOB blob, FILE *fp) image = _keybox_get_blob_image (blob, &length); if (fwrite (image, length, 1, fp) != 1) - return gpg_error (gpg_err_code_from_errno (errno)); + return gpg_error_from_syserror (); return 0; } @@ -154,7 +156,7 @@ _keybox_write_header_blob (FILE *fp) image[20+3] = (val ); if (fwrite (image, 32, 1, fp) != 1) - return gpg_error (gpg_err_code_from_errno (errno)); + return gpg_error_from_syserror (); return 0; } |