Skip to content

Replace memcmp() with zend_string functions #8216

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

Merged
merged 6 commits into from
Mar 31, 2022
Merged

Conversation

MaxKellermann
Copy link
Contributor

No description provided.

@Girgias
Copy link
Member

Girgias commented Mar 18, 2022

This PR is doing too much and unrelated things, can you please split them up into related PRs.

Also IMHO adding and using a newly introduced API should be two different commits.

@MaxKellermann
Copy link
Contributor Author

@Girgias better?

@Girgias
Copy link
Member

Girgias commented Mar 19, 2022

LGTM, but I don't know what our policy is about adding new APIs

@MaxKellermann
Copy link
Contributor Author

Thanks @nikic and @Girgias for the reviews. I rebased and force-pushed with these changes:

  • using zend_string_equals() as suggested, even though it does more than the existing code
  • renamed zend_string_equals_str() to zend_string_equals_cstr() (even though that's not a C string), dropped the old _cstr() function (no shortcut which does strlen())
  • renamed zend_string_starts_with_str() to zend_string_starts_with_cstr()
  • renamed zend_string_starts_with_val() to just zend_string_starts_with() (no suffix = takes zend_string?)

Does that meet your change requests?

Copy link
Member

@iluuu1994 iluuu1994 left a comment

Choose a reason for hiding this comment

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

LGTM

Eliminate duplicate code.
Allows eliminating duplicate code.
This adds missing length checks to several callers, e.g. in
cache_script_in_shared_memory().  This is important when the
zend_string is shorter than the string parameter, when memcmp()
happens to check backwards; this can result in an out-of-bounds memory
access.
@iluuu1994 iluuu1994 changed the title memcmp() out-of-bounds fixes replace memcmp() with zend_string functions Mar 24, 2022
@iluuu1994 iluuu1994 changed the title replace memcmp() with zend_string functions Replace memcmp() with zend_string functions Mar 31, 2022
@iluuu1994 iluuu1994 merged commit b9e895b into php:master Mar 31, 2022
@MaxKellermann
Copy link
Contributor Author

Curious question - @iluuu1994 you folded all commits of this PR into one - why? I took extra care to submit separate commits for separate aspects, to make my work easier to read & review, and to allow bisecting in case of bugs found later. Folding all comits breaks that.
If single-commit PRs are preferred here at php-src, I could save the time for doing separating the commits.

@MaxKellermann MaxKellermann deleted the memcmp-fixes branch March 31, 2022 14:36
@iluuu1994
Copy link
Member

https://wiki.php.net/vcs/gitworkflow

Additionally, the history of pull requests often requires cleanup. For most pull requests, all commits can be squashed into one.

Your commit history is clean but often that's not the case and it makes more sense to squash. I guess in this case either would've been fine.

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

Successfully merging this pull request may close these issues.

4 participants