Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$model->getAttribute(null) causes SIGSEGV #15830

Closed
tmaly1980 opened this issue Oct 9, 2016 · 2 comments
Closed

$model->getAttribute(null) causes SIGSEGV #15830

tmaly1980 opened this issue Oct 9, 2016 · 2 comments

Comments

@tmaly1980
Copy link

tmaly1980 commented Oct 9, 2016

  • Laravel Version: 5.3.10
  • PHP Version: 5.5, 7.0
  • Database Driver & Version: MySQL ???

Description:

Passing a null value to Model::getAttribute causes a segmentation fault, without any explanation, stack trace, error code, etc. I happened to be passing a field from my model, which happened to be a typo in a default scope's creating() function. With Model's __get(), I silently got null from "$model->sietField" (which was a typo):

$model->getAttribute($model->sietField);

I've tested this on PHP 5.5 and 7.0, on MacOS, Linux and Microsoft Azure. I'm guessing it's some sort of infinite recursion, but some sort of error handling would help. Perhaps not allowing null to be passed to getAttribute().

Azure happened to say this as an error message (whereas Linux/MacOS simply did a SIGSEGV):

PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 24 bytes) in D:\home\site\wwwroot\laravel\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php on line 2710

It happens on both the CLI (tinker) and as a server module.

Steps To Reproduce:

Load any model instance and call something like:

use App\User;
$user = new User;
$user->getAttribute(null);

@sisve
Copy link
Contributor

sisve commented Oct 11, 2016

Reproducible with Laravel 5.1.35 on PHP 7.0.10-2+dev.sury.org~trusty+1.

From /var/log/kern.log:

Oct 11 00:42:22 homestead kernel: [125335.114044] php-fpm7.0[8274]: segfault at 7fff3b26dff8 ip 00007fb1a0cddff5 sp 00007fff3b26e000 error 6 in php-fpm7.0[7fb1a0aa3000+38f000]

Looks like a endless recursive call.

  1. getAttribute($key: null)
  2. getAttributeValue($key: null)
  3. hasGetMutator($key: null) and mutateAttribute($key: null, $value: null)
  4. getAttribute($key: null)

A fix would be to have hasGetMutator check if $key is empty.

@themsaid
Copy link
Member

fix proposed in #15874

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants