From 129c01b96fba3ac681828c33b8b0d2a68e110e90 Mon Sep 17 00:00:00 2001 From: Netkas Date: Sat, 17 Jun 2023 04:24:15 -0400 Subject: [PATCH] Updated \TamerLib > tm > addFunction() to validate the function name and check if the function name is reserved --- src/TamerLib/tm.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/TamerLib/tm.php b/src/TamerLib/tm.php index da11340..b747864 100644 --- a/src/TamerLib/tm.php +++ b/src/TamerLib/tm.php @@ -293,7 +293,6 @@ self::$supervisor->spawnWorker($path, $count, $channel); } - var_dump('monitoring'); self::monitor(-1); } @@ -586,6 +585,16 @@ throw new RuntimeException(sprintf('Attempting to addFunction() in \'%s\' mode, only workers can preform addFunction().', self::$mode)); } + if (!preg_match('/^[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*$/', $function)) + { + throw new InvalidArgumentException("Invalid function name: $function"); + } + + if(method_exists(__CLASS__, $function)) + { + throw new InvalidArgumentException(sprintf('Attempting to addFunction() with a function name of \'%s\', this is a reserved function name.', $function)); + } + self::$function_pointers[$function] = $callback; }