From 10622f6dcc5d25a2e3e9b26a5113e7a165a2ff14 Mon Sep 17 00:00:00 2001 From: Andrew Ayer Date: Sat, 6 Sep 2014 14:59:16 -0700 Subject: [PATCH] Raise an error if legacy key file has trailing data --- key.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/key.cpp b/key.cpp index 6b0a512..d8fa482 100644 --- a/key.cpp +++ b/key.cpp @@ -117,6 +117,13 @@ void Key_file::Entry::load_legacy (uint32_t arg_version, std::istream& in) if (in.gcount() != HMAC_KEY_LEN) { throw Malformed(); } + + if (in.peek() != -1) { + // Trailing data is a good indication that we are not actually reading a + // legacy key file. (This is important to check since legacy key files + // did not have any sort of file header.) + throw Malformed(); + } } void Key_file::Entry::store (std::ostream& out) const