From a07f133e5b6be3881ce0beacc3333629b0d9dbd8 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Sun, 16 Dec 2018 22:29:29 -0500 Subject: [PATCH] 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.) --- src/system/kernel/fs/KPath.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/system/kernel/fs/KPath.cpp b/src/system/kernel/fs/KPath.cpp index 3debfbf38f..e0a70bbc72 100644 --- a/src/system/kernel/fs/KPath.cpp +++ b/src/system/kernel/fs/KPath.cpp @@ -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;