exception: Add missing early return for UserNotLoggedIn error page
authorTimo Tijhof <krinklemail@gmail.com>
Mon, 23 Sep 2019 23:33:20 +0000 (00:33 +0100)
committerTimo Tijhof <krinklemail@gmail.com>
Mon, 23 Sep 2019 23:33:20 +0000 (00:33 +0100)
Follows-up d0439af89f6b254c.

If the UserNotLoggedIn class is constructed with an unsupported
message parameter, thrown, and handled by MWExceptionHandler, the
report() method would get called, and it would call the parent,
which stages a full error page and sends it via OutputPage::output.

Due to the missing return statement, it would then still execute
the remaining code, which messes up the internal state of the
already-sent OutputPage object by changing its redirect target
(which will never be used, but might confuse other consumers),
and trying to re-send output() and redirect headers, which will
fail with a warning.

Fixing this is required for T233594 and Iaeaf5e55a586, which allows
ErrorPageError to be "stage only" without ending output. Without
this fix, it would call the parent and do stage-only, but then
the remaining code in this method also work and actually succeed
at sending an invalid message to the user.

To preserve current (accidentally correct) behaviour, this needs
to be fixed first.

Bug: T233594
Bug: T17484
Change-Id: Ic5d73becd889839399a5b425cbbe22a3401acea9

includes/exception/UserNotLoggedIn.php

index 7a99765..246c944 100644 (file)
@@ -80,9 +80,10 @@ class UserNotLoggedIn extends ErrorPageError {
                // since the message may not be compatible.
                if ( !in_array( $this->msg, LoginHelper::getValidErrorMessages() ) ) {
                        parent::report();
+                       return;
                }
 
-               // Message is valid. Redirec to Special:Userlogin
+               // Message is valid. Redirect to Special:Userlogin
 
                $context = RequestContext::getMain();