From 32489dfa569d0247a3175f0b6cf9641e2a6a66c1 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Sun, 20 Jul 2014 23:58:53 +0200 Subject: Fix regex for strange datadirs If a datadir would contain characters with a special meaning in regex (e.g. `/tmp/logs (new)`), then the function would blow up. --- type/Base.class.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/type/Base.class.php b/type/Base.class.php index c3741bd..e18d27a 100644 --- a/type/Base.class.php +++ b/type/Base.class.php @@ -165,6 +165,7 @@ class Type_Base { $this->files = array(); $this->identifiers = array(); + $datadir_prefix = preg_quote($this->datadir, '#'); foreach($files as $filename) { $basename=basename($filename,'.rrd'); $instance = strpos($basename,'-') @@ -173,7 +174,9 @@ class Type_Base { $this->tinstances[] = $instance; $this->files[$instance] = $filename; - $this->identifiers[$instance] = preg_replace("#^$this->datadir/(.*)\.rrd$#", '$1', $filename); + $this->identifiers[$instance] = preg_replace( + "#^{$datadir_prefix}/(.*)\.rrd$#", '$1', + $filename); } sort($this->tinstances); -- cgit v1.1