From 182bc17aebe19f49c30f50aacabdb1c9824c6f68 Mon Sep 17 00:00:00 2001 From: Robin McCorkell Date: Thu, 30 Jul 2015 11:29:06 +0100 Subject: Sanitize class names before registerService/query Leading backslashes are removed, so a `registerService('\\OC\\Foo')` can still be resolved with `query('OC\\Foo')`. --- lib/private/appframework/utility/simplecontainer.php | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lib') diff --git a/lib/private/appframework/utility/simplecontainer.php b/lib/private/appframework/utility/simplecontainer.php index c1fc96d1975..9458d59014a 100644 --- a/lib/private/appframework/utility/simplecontainer.php +++ b/lib/private/appframework/utility/simplecontainer.php @@ -99,6 +99,7 @@ class SimpleContainer extends Container implements IContainer { * @throws QueryException if the query could not be resolved */ public function query($name) { + $name = $this->sanitizeName($name); if ($this->offsetExists($name)) { return $this->offsetGet($name); } else { @@ -128,6 +129,7 @@ class SimpleContainer extends Container implements IContainer { * @param bool $shared */ public function registerService($name, Closure $closure, $shared = true) { + $name = $this->sanitizeName($name); if (isset($this[$name])) { unset($this[$name]); } @@ -151,4 +153,12 @@ class SimpleContainer extends Container implements IContainer { }); } + /* + * @param string $name + * @return string + */ + protected function sanitizeName($name) { + return ltrim($name, '\\'); + } + } -- cgit v1.2.3