From d050670a83a45268df04f299d5daf014b57fe4b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Such=C3=A1nek?= Date: Sat, 5 Apr 2025 14:53:38 +0200 Subject: multiblocks: Prevent reuse of loop variable Why: - BlockIpComplete informs subscribers when a block is placed or updated. - With CONFLICT_NEW, a block can be just inserted, never updated. However, the loop over prior blocks can set $priorBlock to an arbitrary block or keep it null, possibly confusing subscribers of the hook (e.g., by claiming a block is not active anymore). What: - Make sure $priorBlock is always null in this code path. - Also reuse the $priorBlocks array in the loop. Change-Id: I7e6b55a50cb78f77dedc074689dc3fe3b3484a2f --- includes/block/BlockUser.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/includes/block/BlockUser.php b/includes/block/BlockUser.php index aa9ac9269fd4..3de0388d1611 100644 --- a/includes/block/BlockUser.php +++ b/includes/block/BlockUser.php @@ -587,7 +587,6 @@ class BlockUser { } $expectedTargetCount = 0; - $priorBlock = null; $priorBlocks = $this->getPriorBlocksForTarget(); if ( $this->blockToUpdate !== null ) { @@ -601,7 +600,7 @@ class BlockUser { } elseif ( $conflictMode === self::CONFLICT_NEW && $this->options->get( MainConfigNames::EnableMultiBlocks ) ) { - foreach ( $this->getPriorBlocksForTarget() as $priorBlock ) { + foreach ( $priorBlocks as $priorBlock ) { if ( $block->equals( $priorBlock ) ) { // Block settings are equal => user is already blocked $this->logger->debug( 'placeBlockInternal: ' . @@ -610,8 +609,10 @@ class BlockUser { } } $expectedTargetCount = null; + $priorBlock = null; $update = false; } elseif ( !$priorBlocks ) { + $priorBlock = null; $update = false; } else { // Reblock only if the caller wants so -- cgit v1.2.3