apm-agent-php: Segfault when `opcache.restrict_api` is used

Describe the bug

With agent v1.9.0 (#1000) we try and call opcache_get_status() to detect if opcache is in a pending restart state.

There’s an option opcache.restrict_api that can be set to restrict which scripts are allowed to call opcache functions. This setting is useful in a multi-tenant environment to restrict opcache management to a few controlled endpoints. When this setting is set those paths not in the whitelist are prevented from calling opcache functions and this appears to trigger a segfault with the APM agent module.

To Reproduce

Steps to reproduce the behavior:

  1. Use APM Agent 1.9.0
  2. Set opcache.restrict_api to any arbitrary path
  3. Enable APM Agent and trigger a render on any path that is not within the above given restrict_api path.

Expected behavior

No segfault should happen, perhaps the detectOpcacheRestartPending() function should just short-circuit and return false if the current script is not within the opcache.restrict_api path.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 16 (6 by maintainers)

Commits related to this issue

Most upvoted comments

Hey @xyu Thank you for testing. I prepared PR with a next fix - I did it the way you suggested on beginning - by comparing script name with restrict_api configuration.

pull-request

branch in my fork

Please rebuild agent from this branch and give it a try.

BTW, could you share a reason why you’re building agent from source and not using built packages?

Regards, Pawel