From 110078022a6c6103be8f557aef1e268c4b680d88 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 20 Feb 2020 12:49:15 +0100 Subject: Parse records including empty tag names correctly No sensible file should include these, but even insensible files do not gain unfair advantages with it as this parser does not deal with security critical files before they haven't passed other checks like signatures or hashsums. The problem is that the parser accepts and parses empty tag names correctly, but does not store the data parsed which will effect later passes over the data resulting e.g. in the following tag containing the name and value of the previous (empty) tag, its own tagname and its own value or a crash due to an attempt to access invalid memory depending on who passes over the data and what is done with it. This commit fixes both, the incidient of the crash reported by Anatoly Trosinenko who reproduced it via apt-sortpkgs: | $ cat /tmp/Packages-null | 0: | PACKAGE:0 | | : | PACKAGE: | | PACKAGE:: | $ apt-sortpkgs /tmp/Packages-null and the deeper parsing issue shown by the included testcase. Reported-By: Anatoly Trosinenko References: 8710a36a01c0cb1648926792c2ad05185535558e --- apt-pkg/tagfile.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'apt-pkg/tagfile.cc') diff --git a/apt-pkg/tagfile.cc b/apt-pkg/tagfile.cc index 0f0d8c9a7..52000c6b9 100644 --- a/apt-pkg/tagfile.cc +++ b/apt-pkg/tagfile.cc @@ -513,7 +513,6 @@ bool pkgTagSection::Scan(const char *Start,unsigned long MaxLength, bool const R return false; pkgTagSectionPrivate::TagData lastTagData(0); - lastTagData.EndTag = 0; Key lastTagKey = Key::Unknown; unsigned int lastTagHash = 0; while (Stop < End) @@ -529,7 +528,7 @@ bool pkgTagSection::Scan(const char *Start,unsigned long MaxLength, bool const R if (isspace_ascii(Stop[0]) == 0) { // store the last found tag - if (lastTagData.EndTag != 0) + if (lastTagData.StartValue != 0) { if (lastTagKey != Key::Unknown) { AlphaIndexes[static_cast(lastTagKey)] = TagCount; @@ -579,7 +578,7 @@ bool pkgTagSection::Scan(const char *Start,unsigned long MaxLength, bool const R // Double newline marks the end of the record if (Stop+1 < End && Stop[1] == '\n') { - if (lastTagData.EndTag != 0) + if (lastTagData.StartValue != 0) { if (lastTagKey != Key::Unknown) { AlphaIndexes[static_cast(lastTagKey)] = TagCount; -- cgit v1.2.3