Skip to content

zend: introducing ZEND_ELEMENT_COUNT for struct's dynamic arrays. #12650

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 3 commits into from
Nov 13, 2023

Conversation

devnexen
Copy link
Member

It is mostly for ubsan and helping array bound checking.

It is mostly for ubsan and helping array bound checking.
@nielsdos
Copy link
Member

This is a really nice feature that I've seen used in Linux too to prevent bugs. I'm not sure if element_count is actually already implemented (seems like the feature request is open atm), but counted_by is available in Clang.

@devnexen
Copy link
Member Author

yes for gcc it s still in review.

@iluuu1994
Copy link
Member

Does this work on structs with the struct hack? (i.e. last_element[1]) We have a few of those, you can search by \*\w+\[1\];, although I'm not sure how many apply.

@devnexen
Copy link
Member Author

I ve tried with zend_type_list locally, seems to work. I ve tried the limit of it, changing to pointers or non integral counters and it fails to compile rightfully for those.

@iluuu1994
Copy link
Member

Great, thank you! My regex was sub-optimal for obvious reasons (* requirement). I used another one (\w+\[(0|1)?\];\n\}) and found more candidates:

  • zend_ffi_callback_data
  • cdf_catalog_t
  • zend_jit_trace_stack_frame
  • ir_refs
  • fpm_scoreboard_s
  • phpdbg_file_source
  • zend_ast_list
  • zend_attribute
  • zend_type_list
  • zend_string
  • zend_property_info_list
  • zend_trait_precedence
  • zend_inheritance_cache_entry
  • zend_call_info

Copy link
Member

@dstogov dstogov left a comment

Choose a reason for hiding this comment

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

Looks fine.

@devnexen devnexen merged commit cc2bf11 into php:master Nov 13, 2023
@bukka
Copy link
Member

bukka commented Nov 13, 2023

It would be good to eventually get rid of the struct hack as well to also make builtin size checks work. Remember reading this article about work that is being done in Linux kernel for that: https://lwn.net/Articles/908817/

@morrisonlevi
Copy link
Contributor

morrisonlevi commented Nov 13, 2023

As far as I understand it, using flexible array members is no-go because we support C++ compilers to interpret our headers. C++ still doesn't support flexible array members. So until we have a strategy for that, I don't think we can get rid of the struct hack.

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

Successfully merging this pull request may close these issues.

6 participants