Skip to content

Commit

Permalink
libemeber: Avoid dereferencing a null pointer when Container::insert(…
Browse files Browse the repository at this point in the history
…) is invoked with an invalid child node.

Thanks to Johannes Freyberger <[email protected]> for the
identifying the issue and proposing a fix.
  • Loading branch information
KimonHoffmann committed Aug 28, 2024
1 parent b42f314 commit bbaa1b4
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions libember/Headers/ember/dom/impl/Container.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <stdexcept>
#include "../../util/Inline.hpp"

namespace libember { namespace dom
namespace libember { namespace dom
{
LIBEMBER_INLINE
Container::Container(ber::Tag tag)
Expand All @@ -33,14 +33,24 @@ namespace libember { namespace dom
LIBEMBER_INLINE
Container::iterator Container::insert(iterator const& where, Node* child)
{
if (child->parent() != 0)
if (child != 0)
{
throw std::runtime_error("Attempt to add a node already owned by a container node.");
if (child->parent() == 0)
{
iterator const result = insertImpl(where, child);
result->setParent(this);
markDirty();
return result;
}
else
{
throw std::runtime_error("Attempt to add a node already owned by a container node.");
}
}
else
{
throw std::runtime_error("Attempt to add an invalid child node.");
}
iterator const result = insertImpl(where, child);
result->setParent(this);
markDirty();
return result;
}

LIBEMBER_INLINE
Expand Down

0 comments on commit bbaa1b4

Please sign in to comment.