diff options
author | Werner Koch <[email protected]> | 2014-10-09 18:19:05 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2014-10-09 18:19:05 +0000 |
commit | b6507bb80e4e4aa5c85a918fdcf5c28cccb75081 (patch) | |
tree | 6892ed42e79aea6233da23439283079a02e9a279 /kbx/keybox-dump.c | |
parent | gpg: Take care to use pubring.kbx if it has ever been used. (diff) | |
download | gnupg-b6507bb80e4e4aa5c85a918fdcf5c28cccb75081.tar.gz gnupg-b6507bb80e4e4aa5c85a918fdcf5c28cccb75081.zip |
kbx: Fix handling of overlong keys.
* kbx/keybox-file.c (IMAGELEN_LIMIT): Change limit from 10^6 to 2MiB.
(_keybox_read_blob2): Skip too long record records.
(_keybox_write_blob): Do not accept too long record.
* kbx/keybox-dump.c (file_stats_s): Add field skipped_long_blobs.
(_keybox_dump_file): Print new counter.
(_keybox_dump_file): Skip too long records.
----
To test this feature you may set the limit back to 1MiB and use key
F7F0E70F307D56ED which is in my local copy close to 2MiB. Without
this patch it was possible to import the key but access to that key
and all keys stored after it was not possible.
Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'kbx/keybox-dump.c')
-rw-r--r-- | kbx/keybox-dump.c | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/kbx/keybox-dump.c b/kbx/keybox-dump.c index bfe7b4899..dfa82007f 100644 --- a/kbx/keybox-dump.c +++ b/kbx/keybox-dump.c @@ -491,6 +491,7 @@ struct file_stats_s unsigned long non_flagged; unsigned long secret_flagged; unsigned long ephemeral_flagged; + unsigned long skipped_long_blobs; }; static int @@ -594,8 +595,25 @@ _keybox_dump_file (const char *filename, int stats_only, FILE *outfp) if (!(fp = open_file (&filename, outfp))) return gpg_error_from_syserror (); - while ( !(rc = _keybox_read_blob (&blob, fp)) ) + for (;;) { + rc = _keybox_read_blob (&blob, fp); + if (gpg_err_code (rc) == GPG_ERR_TOO_LARGE + && gpg_err_source (rc) == GPG_ERR_SOURCE_KEYBOX) + { + if (stats_only) + stats.skipped_long_blobs++; + else + { + fprintf (outfp, "BEGIN-RECORD: %lu\n", count ); + fprintf (outfp, "# Record too large\nEND-RECORD\n"); + } + count++; + continue; + } + if (rc) + break; + if (stats_only) { update_stats (blob, &stats); @@ -612,7 +630,7 @@ _keybox_dump_file (const char *filename, int stats_only, FILE *outfp) if (rc == -1) rc = 0; if (rc) - fprintf (outfp, "error reading '%s': %s\n", filename, gpg_strerror (rc)); + fprintf (outfp, "# error reading '%s': %s\n", filename, gpg_strerror (rc)); if (fp != stdin) fclose (fp); @@ -636,14 +654,17 @@ _keybox_dump_file (const char *filename, int stats_only, FILE *outfp) stats.non_flagged, stats.secret_flagged, stats.ephemeral_flagged); + if (stats.skipped_long_blobs) + fprintf (outfp, " skipped long blobs: %8lu\n", + stats.skipped_long_blobs); if (stats.unknown_blob_count) fprintf (outfp, " unknown blob types: %8lu\n", stats.unknown_blob_count); if (stats.too_short_blobs) - fprintf (outfp, " too short blobs: %8lu\n", + fprintf (outfp, " too short blobs: %8lu (error)\n", stats.too_short_blobs); if (stats.too_large_blobs) - fprintf (outfp, " too large blobs: %8lu\n", + fprintf (outfp, " too large blobs: %8lu (error)\n", stats.too_large_blobs); } |