Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Prevent potential buffer overflow for large value of php_cli_server_workers_max #9000

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

Closed
yiyuaner wants to merge 1 commit into php:master from yiyuaner:master

Conversation

Copy link
Contributor

@yiyuaner yiyuaner commented Jul 13, 2022

Fixes issue 8989.

Copy link
Member

cmb69 commented Jul 13, 2022

Thank you for the PR! I don't like the silent fall back to 1 worker, though. Can't we use safe_emalloc() instead of calloc() (fails hard if unsuccessful), and clear the memory afterwards?

Copy link
Member

I agree here in the sense it s not correct to hide it, you can possibly catch out of range from the value before allocation (like nginx does to catch silly values for its worker processes) or as @cmb69 said, either way need clarity from user's perspective.

cmb69 reacted with thumbs up emoji

Copy link
Contributor Author

If I understand it correctly, replacing calloc with safe_emalloc can resolve this. When integer overflow happens, an error message is printed and the program aborts.

php_cli_server_workers = calloc(
php_cli_server_workers_max, sizeof(pid_t));
php_cli_server_workers = safe_emalloc(
php_cli_server_workers_max, sizeof(pid_t), 0);
Copy link
Member

@devnexen devnexen Jul 14, 2022
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two keys here:
1/ > and clear the memory afterwards.
since you re moving from calloc.
2/ You might need a change for free(php_cli_server_workers).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. I have replaced it with efree.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. Don t forget the first point :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ecalloc is a safe version of calloc that checks for multiply overflow. I think it can be used here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, @cmb69 will have a last look in case I missed something. Nice work.

@yiyuaner yiyuaner force-pushed the master branch 2 times, most recently from 2822fb3 to 8cb3735 Compare July 14, 2022 05:14
zend_long php_cli_server_worker;

php_cli_server_workers = calloc(
php_cli_server_workers = ecalloc(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ecalloc() and friends allocate memory which is freed at the end of each request. That would cause issues here. Instead you'd need pecalloc() with the third argument being 1 (and use pefree() instead of efree() above). Note that the Zend memory allocation functions are infallible, i.e. they never return NULL (but instead terminate the process), so the following NULL check is superfluous.

devnexen and mikkorantalainen reacted with thumbs up emoji
Copy link
Member

@cmb69 cmb69 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

yiyuaner reacted with thumbs up emoji
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@devnexen devnexen devnexen left review comments

@cmb69 cmb69 cmb69 approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /