Open jeristiano opened 3 years ago
Describe the bug
使用swoft rpc-client 调用微服务时出现:
[ERROR] App\Exception\Handler\HttpExceptionHandler:handle(40) Undefined offset: 1. (At /var/www/html/card_rpc/vendor/swoft/rpc-client/src/Concern/ServiceTrait.php line 87)
Screenshots
Details
定义微服务接口方法参数存在默认值,例如:encrypt (string $value, string $field = 'default'),客户端发起调用rpc服务,第二个参数($field)不传参,那么将会得到以上错误。跟踪代码发现问题出现在服务端的limiter组件
报错位置 :
// \Swoft\Limiter\RateLimter::evaluateKey private function evaluateKey(string $key, string $className, string $method, array $params): string { $values = []; $rcMethod = Reflections::get($className); $rcParams = $rcMethod['methods'][$method]['params'] ?? []; $index = 0; foreach ($rcParams as $rcParam) { [$pName] = $rcParam; $values[$pName] = $params[$index]; //此处由于没有对数组做越界处理,导致 Undefined offset: 2 $index++; } // Inner vars $values['CLASS'] = $className; $values['METHOD'] = $method; // Parse express language $el = new ExpressionLanguage(); return $el->evaluate($key, $values); }
How to fix
... $values[$pName] = $params[$index]??null; // 建议此处进行越界处理 ...
Describe the bug
使用swoft rpc-client 调用微服务时出现:
Screenshots
Details
报错位置 :
How to fix