Skip to content
Permalink
Browse files
Client crashfix: load meta after digging (#5801)
Fixes a crash caused in MTGame by breaking and right-clicking a chest.

If loading meta, digging, node can disappear and we looked at meta, which is wrong because meta became NULL.

Pointer is invalidated and we read wrong memory area
  • Loading branch information
paramat authored and nerzhul committed May 23, 2017
1 parent 0530922 commit 9ff5302c8bf1cc270ca144c9f2cfcb99f6903605
Showing 1 changed file with 10 additions and 9 deletions.
@@ -3744,6 +3744,13 @@ void Game::handlePointingAtNode(const PointedThing &pointed, const ItemDefinitio
*/

ClientMap &map = client->getEnv().getClientMap();

if (runData.nodig_delay_timer <= 0.0 && isLeftPressed()
&& client->checkPrivilege("interact")) {
handleDigging(pointed, nodepos, playeritem_toolcap, dtime);
}

// This should be done after digging handling
NodeMetadata *meta = map.getNodeMetadata(nodepos);

if (meta) {
@@ -3757,11 +3764,6 @@ void Game::handlePointingAtNode(const PointedThing &pointed, const ItemDefinitio
}
}

if (runData.nodig_delay_timer <= 0.0 && isLeftPressed()
&& client->checkPrivilege("interact")) {
handleDigging(pointed, nodepos, playeritem_toolcap, dtime);
}

if ((getRightClicked() ||
runData.repeat_rightclick_timer >= m_repeat_right_click_time) &&
client->checkPrivilege("interact")) {
@@ -3977,10 +3979,9 @@ void Game::handleDigging(const PointedThing &pointed, const v3s16 &nodepos,
bool is_valid_position;
MapNode wasnode = map.getNodeNoEx(nodepos, &is_valid_position);
if (is_valid_position) {
if (client->moddingEnabled()) {
if (client->getScript()->on_dignode(nodepos, wasnode)) {
return;
}
if (client->moddingEnabled() &&
client->getScript()->on_dignode(nodepos, wasnode)) {
return;
}
client->removeNode(nodepos);
}

0 comments on commit 9ff5302

Please sign in to comment.