summaryrefslogtreecommitdiffstats
path: root/tool/src/commands
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2020-08-06 11:58:30 +0200
committerJustus Winter <justus@sequoia-pgp.org>2020-08-06 11:58:30 +0200
commita8f36b02e6c42706ea6fa234a7ff8872d2b4b7f9 (patch)
tree49d63190ceb18e897d4407779a3529e461c23721 /tool/src/commands
parentaaeb3447b692819bfb16990dfdd44d384eff1e14 (diff)
sq: Make dumping corrupted OpenPGP data more robust.
- Previously, sq packet dump would often fail without dumping any packets, even if a prefix of the data could be successfully parsed. - To fix this, we need to do two things. First, we need to clone the packet while it is in the parser *before* we advance the parser, which could potentially fail. Second, we need to flush the output once the parser fails. - Fixes #524.
Diffstat (limited to 'tool/src/commands')
-rw-r--r--tool/src/commands/dump.rs12
1 files changed, 10 insertions, 2 deletions
diff --git a/tool/src/commands/dump.rs b/tool/src/commands/dump.rs
index 17c3b474..a1ddb043 100644
--- a/tool/src/commands/dump.rs
+++ b/tool/src/commands/dump.rs
@@ -138,11 +138,19 @@ pub fn dump<W>(input: &mut dyn io::Read, output: &mut dyn io::Write,
let map = pp.take_map();
let recursion_depth = pp.recursion_depth();
- let (packet, ppr_) = pp.recurse()?;
- ppr = ppr_;
+ let packet = pp.packet.clone();
dumper.packet(output, recursion_depth as usize,
header, packet, map, additional_fields)?;
+
+ let (_, ppr_) = match pp.recurse() {
+ Ok(v) => Ok(v),
+ Err(e) => {
+ let _ = dumper.flush(output);
+ Err(e)
+ },
+ }?;
+ ppr = ppr_;
}
dumper.flush(output)?;