From 942be407ee8b6ca1089ed9c2f135ca4ed89c44fc Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Thu, 20 Feb 2020 13:25:10 +0100 Subject: tagfile: Check if memchr() returned null before using This fixes a segmentation fault trying to read from nullptr+1, aka address 1. --- apt-pkg/tagfile.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 ""; -- cgit v1.2.3