Kaydet (Commit) 4058d859 authored tarafından Ashod Nakashian's avatar Ashod Nakashian Kaydeden (comit) Ashod Nakashian

PPDCache: fix segfault due to access after delete

Regression introduced in:

    commit afe4d252
    Author: Noel Grandin <noel.grandin@collabora.co.uk>
    Date:   Wed Oct 18 09:43:21 2017 +0200

        use std::unique_ptr in PPDCache

Removing a naked pointer before inserting a possibly existing
one in a container is safe. This insured uniqueness (as the
comment suggests). However with unique_ptr, removal before
inserting deletes the pointer (when it exists), and the
insertion now taints the container with a wild pointer.

The fix is to skip adding if the pointer is already in the
container and add only when missing.

Change-Id: Ifc6b517451abb564949ccadfee10d98bf827540d
Reviewed-on: https://gerrit.libreoffice.org/44333Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarAshod Nakashian <ashnakash@gmail.com>
üst 3b4fd349
...@@ -576,15 +576,15 @@ const PPDParser* PPDParser::getParser( const OUString& rFile ) ...@@ -576,15 +576,15 @@ const PPDParser* PPDParser::getParser( const OUString& rFile )
if( pNewParser ) if( pNewParser )
{ {
// this may actually be the SGENPRT parser, // this may actually be the SGENPRT parser,
// so ensure uniqueness here // so ensure uniqueness here (but don't remove lest we delete us!)
rPPDCache.aAllParsers.erase( if (std::find_if(
std::remove_if(
rPPDCache.aAllParsers.begin(), rPPDCache.aAllParsers.begin(),
rPPDCache.aAllParsers.end(), rPPDCache.aAllParsers.end(),
[pNewParser] (std::unique_ptr<PPDParser> const & x) { return x.get() == pNewParser; } ), [pNewParser] (std::unique_ptr<PPDParser> const & x) { return x.get() == pNewParser; } ) == rPPDCache.aAllParsers.end())
rPPDCache.aAllParsers.end()); {
// insert new parser to vector // insert new parser to vector
rPPDCache.aAllParsers.emplace_back(pNewParser); rPPDCache.aAllParsers.emplace_back(pNewParser);
}
} }
return pNewParser; return pNewParser;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment