libnetapi: Fix use after free

Fix 'fImpl' is used after delete in BNetBuffer::operator=
(GetImpl() returns fImpl), when it is used with self assignment.
Pointed out by Clang Static Analyzer.

Change-Id: Ic80a4ce73879062581b9241f84a4340919d281b9
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3393
Reviewed-by: Jérôme Duval <jerome.duval@gmail.com>
This commit is contained in:
Murai Takashi 2020-11-13 21:28:31 +09:00 committed by Adrien Destugues
parent a756a8ad1b
commit 6c016dc54a

View File

@ -66,12 +66,13 @@ BNetBuffer::BNetBuffer(BMessage* archive) :
BNetBuffer&
BNetBuffer::operator=(const BNetBuffer& buffer)
{
delete fImpl;
fImpl = new (std::nothrow) DynamicBuffer(*buffer.GetImpl());
if (fImpl != NULL)
fInit = fImpl->InitCheck();
if (&buffer != this) {
delete fImpl;
fImpl = new (std::nothrow) DynamicBuffer(*buffer.GetImpl());
if (fImpl != NULL)
fInit = fImpl->InitCheck();
}
return *this;
}