Page MenuHomePhabricator

User::__toString() can return a non-string, causing fatal errors
Closed, ResolvedPublic

Description

Initially reported and debugged at https://github.com/SimpleMachines/smf-mw-auth/issues/10

In User::doLogout():

			\MediaWiki\Logger\LoggerFactory::getInstance( 'session' )
				->warning( __METHOD__ .
					": Cannot log user \"$this\" out of a user \"{$session->getUser()}\"'s session"
				);

relying upon the implicit $this->__toString().

	public function __toString() {
		return $this->getName();
	}

okay looks fine,

getName() calls IP::sanitizeIP which can return null. Unsure why that is returning null, but we should at least make sure __toString() always returns a string, or throw an error earlier in the stack.

Event Timeline

Change 316721 had a related patch set uploaded (by Gergő Tisza):
Force User::__toString() return value to be string

https://gerrit.wikimedia.org/r/316721

Change 316721 merged by jenkins-bot:
Force User::__toString() return value to be string

https://gerrit.wikimedia.org/r/316721

Tgr claimed this task.

Should we backport to REL1_27?

Change 316729 had a related patch set uploaded (by Gergő Tisza):
Force User::__toString() return value to be string

https://gerrit.wikimedia.org/r/316729

Change 316729 merged by jenkins-bot:
Force User::__toString() return value to be string

https://gerrit.wikimedia.org/r/316729