summaryrefslogtreecommitdiff
path: root/apt-pkg/tagfile.cc
diff options
context:
space:
mode:
authorJulian Andres Klode <julian.klode@canonical.com>2020-02-20 13:25:10 +0100
committerJulian Andres Klode <julian.klode@canonical.com>2020-02-20 13:35:27 +0100
commit942be407ee8b6ca1089ed9c2f135ca4ed89c44fc (patch)
treee9002997b12456b3a1a496a0cfb5f2a8dc3e231a /apt-pkg/tagfile.cc
parentc8821bb424e2324a36896dcccaef573c938c5b0e (diff)
tagfile: Check if memchr() returned null before using
This fixes a segmentation fault trying to read from nullptr+1, aka address 1.
Diffstat (limited to 'apt-pkg/tagfile.cc')
-rw-r--r--apt-pkg/tagfile.cc7
1 files changed, 6 insertions, 1 deletions
diff --git a/apt-pkg/tagfile.cc b/apt-pkg/tagfile.cc
index bbece1d7e..b86936353 100644
--- a/apt-pkg/tagfile.cc
+++ b/apt-pkg/tagfile.cc
@@ -714,8 +714,13 @@ StringView pkgTagSection::Find(Key key) const
StringView pkgTagSection::FindRawInternal(unsigned int Pos) const
{
char const *Start = (char const *) memchr(Section + d->Tags[Pos].EndTag, ':', d->Tags[Pos].StartValue - d->Tags[Pos].EndTag);
- ++Start;
char const *End = Section + d->Tags[Pos + 1].StartTag;
+
+ if (Start == nullptr)
+ return "";
+
+ ++Start;
+
if (unlikely(Start > End))
return "";