KPath: Prevent setting a KPath to itself causing use-after-free.

SetTo frees the buffer before setting it to the new one,
but if KPath sets itself to ... itself, then it will of course
try to access the buffer again.

Spotted by clang-analyzer (amidst quite a few false positives,
so this doesn't seem like an especially good rabbit hole
to go down right now.)
This commit is contained in:
Augustin Cavalier
2018-12-16 22:29:29 -05:00
parent a41ed241d9
commit a07f133e5b
+3
View File
@@ -356,6 +356,9 @@ KPath::Normalize(bool traverseLeafLink)
KPath&
KPath::operator=(const KPath& other)
{
if (other.fBuffer == fBuffer)
return *this;
SetTo(other.fBuffer, fLazy ? KPath::LAZY_ALLOC : KPath::DEFAULT,
other.fBufferSize);
return *this;