diff options
author | Guillem Jover <guillem@debian.org> | 2015-03-19 22:51:46 +0100 |
---|---|---|
committer | Guillem Jover <guillem@debian.org> | 2015-05-09 04:59:06 +0200 |
commit | aea291e3db1ac0414dcf005a0a607e78bdd77a5e (patch) | |
tree | 8cffd4ea8236b2016705e0b327e038b054503d62 /scripts/Dpkg/Control/HashCore.pm | |
parent | 60b2a4fa317f0b473043b13fff16c52a812ad800 (diff) | |
download | dpkg-aea291e3db1ac0414dcf005a0a607e78bdd77a5e.tar.gz |
Dpkg::Control::HashCore: Fix OpenPGP Armor Header Line parsing
Cherry picked from commit b4ccfe4982161b8beb44f1d0c98f791c4f238edd.
We should only accept [\r\t ] as trailing whitespace, although RFC4880
does not clarify what whitespace really maps to, we should really match
the GnuPG implementation anyway, as that is what we use to verify the
signatures.
Fixes: CVE-2015-0840
Reported-by: Jann Horn <jann@thejh.net>
Diffstat (limited to 'scripts/Dpkg/Control/HashCore.pm')
-rw-r--r-- | scripts/Dpkg/Control/HashCore.pm | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/scripts/Dpkg/Control/HashCore.pm b/scripts/Dpkg/Control/HashCore.pm index 2646ade08..4162ad95f 100644 --- a/scripts/Dpkg/Control/HashCore.pm +++ b/scripts/Dpkg/Control/HashCore.pm @@ -197,8 +197,8 @@ sub parse { local $_; while (<$fh>) { - s/\s*\n$//; - next if length == 0 and $paraborder; + chomp; + next if m/^\s*$/ and $paraborder; next if (m/^#/); $paraborder = 0; if (m/^(\S+?)\s*:\s*(.*)$/) { @@ -212,6 +212,7 @@ sub parse { $self->parse_error($desc, g_('duplicate field %s found'), $name); } } + $value =~ s/\s*$//; $self->{$name} = $value; $cf = $name; } elsif (m/^\s(\s*\S.*)$/) { @@ -222,8 +223,9 @@ sub parse { if ($line =~ /^\.+$/) { $line = substr $line, 1; } + $line =~ s/\s*$//; $self->{$cf} .= "\n$line"; - } elsif (m/^-----BEGIN PGP SIGNED MESSAGE-----$/) { + } elsif (m/^-----BEGIN PGP SIGNED MESSAGE-----[\r\t ]*$/) { $expect_pgp_sig = 1; if ($$self->{allow_pgp} and not $parabody) { # Skip OpenPGP headers @@ -233,7 +235,8 @@ sub parse { } else { $self->parse_error($desc, g_('OpenPGP signature not allowed here')); } - } elsif (length == 0 || ($expect_pgp_sig && m/^-----BEGIN PGP SIGNATURE-----$/)) { + } elsif (m/^\s*$/ || + ($expect_pgp_sig && m/^-----BEGIN PGP SIGNATURE-----[\r\t ]*$/)) { if ($expect_pgp_sig) { # Skip empty lines $_ = <$fh> while defined && m/^\s*$/; @@ -241,15 +244,15 @@ sub parse { $self->parse_error($desc, g_('expected OpenPGP signature, ' . 'found end of file after blank line')); } - s/\s*\n$//; - unless (m/^-----BEGIN PGP SIGNATURE-----$/) { + chomp; + unless (m/^-----BEGIN PGP SIGNATURE-----[\r\t ]*$/) { $self->parse_error($desc, g_('expected OpenPGP signature, ' . - "found something else '%s'"), $_); + "found something else \`%s'"), $_); } # Skip OpenPGP signature while (<$fh>) { - s/\s*\n$//; - last if m/^-----END PGP SIGNATURE-----$/; + chomp; + last if m/^-----END PGP SIGNATURE-----[\r\t ]*$/; } unless (defined) { $self->parse_error($desc, g_('unfinished OpenPGP signature')); |