summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSmallJoker <SmallJoker@users.noreply.github.com>2021-05-29 11:44:48 +0200
committerGitHub <noreply@github.com>2021-05-29 11:44:48 +0200
commit5bf72468f3a0925a9fc3c9acacf3f6e138bff35e (patch)
treef4176ee197cf895c881c14d2162d3df6e5629577 /src
parentff48619a857da2158768314f08191994b33ffee9 (diff)
downloadminetest-5bf72468f3a0925a9fc3c9acacf3f6e138bff35e.tar.gz
minetest-5bf72468f3a0925a9fc3c9acacf3f6e138bff35e.tar.bz2
minetest-5bf72468f3a0925a9fc3c9acacf3f6e138bff35e.zip
UnitSAO: Prevent circular attachments
Diffstat (limited to 'src')
-rw-r--r--src/server/unit_sao.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/server/unit_sao.cpp b/src/server/unit_sao.cpp
index fa6c8f0f4..acbdd478a 100644
--- a/src/server/unit_sao.cpp
+++ b/src/server/unit_sao.cpp
@@ -124,6 +124,19 @@ void UnitSAO::sendOutdatedData()
void UnitSAO::setAttachment(int parent_id, const std::string &bone, v3f position,
v3f rotation, bool force_visible)
{
+ auto *obj = parent_id ? m_env->getActiveObject(parent_id) : nullptr;
+ if (obj) {
+ // Do checks to avoid circular references
+ // The chain of wanted parent must not refer or contain "this"
+ for (obj = obj->getParent(); obj; obj = obj->getParent()) {
+ if (obj == this) {
+ warningstream << "Mod bug: Attempted to attach object " << m_id << " to parent "
+ << parent_id << " but former is an (in)direct parent of latter." << std::endl;
+ return;
+ }
+ }
+ }
+
// Attachments need to be handled on both the server and client.
// If we just attach on the server, we can only copy the position of the parent.
// Attachments are still sent to clients at an interval so players might see them