Skip to content

Commit 453fb73

Browse files
authored
Merge commit from fork
Security advisory GHSA-356v-7xg2-3678
1 parent c55018e commit 453fb73

File tree

1 file changed

+43
-23
lines changed

1 file changed

+43
-23
lines changed

main/inc/lib/nusoap/class.soap_server.php

Lines changed: 43 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -586,34 +586,54 @@ function invoke_method() {
586586
$this->appendDebug($this->varDump($this->methodparams));
587587
$this->debug("in invoke_method, calling '$this->methodname'");
588588
if (!function_exists('call_user_func_array')) {
589-
if ($class == '') {
590-
$this->debug('in invoke_method, calling function using eval()');
591-
$funcCall = "\$this->methodreturn = $this->methodname(";
592-
} else {
593-
if ($delim == '..') {
594-
$this->debug('in invoke_method, calling class method using eval()');
595-
$funcCall = "\$this->methodreturn = ".$class."::".$method."(";
589+
try {
590+
if ($class == '') {
591+
$this->debug('in invoke_method, calling function using eval()');
592+
$reflectionFunction = new ReflectionFunction($this->methodname);
593+
$params = $reflectionFunction->getParameters();
594+
595+
if (count($params) !== count($this->methodparams)) {
596+
$this->fault('SOAP-ENV:Client', "Paremeter count mismatch");
597+
return;
598+
}
599+
600+
$this->methodreturn = $reflectionFunction->invokeArgs(array_values($this->methodparams));
596601
} else {
597-
$this->debug('in invoke_method, calling instance method using eval()');
598-
// generate unique instance name
599-
$instname = "\$inst_".time();
600-
$funcCall = $instname." = new ".$class."(); ";
601-
$funcCall .= "\$this->methodreturn = ".$instname."->".$method."(";
602-
}
603-
}
604-
if ($this->methodparams) {
605-
foreach ($this->methodparams as $param) {
606-
if (is_array($param) || is_object($param)) {
607-
$this->fault('SOAP-ENV:Client', 'NuSOAP does not handle complexType parameters correctly when using eval; call_user_func_array must be available');
602+
$reflectionMethod = new ReflectionMethod($class, $method);
603+
$params = $reflectionMethod->getParameters();
604+
605+
if (count($params) !== count($this->methodparams)) {
606+
$this->fault('SOAP-ENV:Client', "Paremeter count mismatch");
608607
return;
609608
}
610-
$funcCall .= "\"$param\",";
609+
610+
$instance = null;
611+
612+
if ($delim == '..') {
613+
if (!$reflectionMethod->isStatic()) {
614+
throw new Exception("Method '$method' is not static");
615+
}
616+
} else {
617+
if ($reflectionMethod->isStatic()) {
618+
throw new Exception("Method '$method' is static");
619+
}
620+
621+
$instance = new $class();
622+
}
623+
624+
$this->methodreturn = $reflectionMethod->invokeArgs($instance, array_values($this->methodparams));
611625
}
612-
$funcCall = substr($funcCall, 0, -1);
626+
627+
$this->debug('in invoke_method, methodreturn: ' . $this->varDump($this->methodreturn));
628+
} catch (ReflectionException $e) {
629+
$this->fault('SOAP-ENV:Client', 'Error invoking method: '.$e->getMessage());
630+
631+
return;
632+
} catch (Exception $e) {
633+
$this->fault('SOAP-ENV:Client', $e->getMessage());
634+
635+
return;
613636
}
614-
$funcCall .= ');';
615-
$this->debug('in invoke_method, function call: '.$funcCall);
616-
@eval($funcCall);
617637
} else {
618638
if ($class == '') {
619639
$this->debug('in invoke_method, calling function using call_user_func_array()');

0 commit comments

Comments
 (0)