Skip to content

INIT_CLASS_ENTRY should use strlen() to determine class name length #10217

Closed

Description

Description

This works:

INIT_CLASS_ENTRY(ce, "mylongclassname", methods);

This does not:

void register_class(zend_class_entry * ce, const char * name, const zend_function_entry * methods) {
    INIT_CLASS_ENTRY(ce, name, methods);
}

register_class(ce, "mylongclassname", methods);

Because INIT_OVERLOADED_CLASS_ENTRY uses sizeof() to determine class_name_len:

#define INIT_OVERLOADED_CLASS_ENTRY(class_container, class_name, functions, handle_fcall, handle_propget, handle_propset) \
	INIT_OVERLOADED_CLASS_ENTRY_EX(class_container, class_name, sizeof(class_name)-1, functions, handle_fcall, handle_propget, handle_propset, NULL, NULL

PHP Version

All

Operating System

All

Activity

  1. ghost added on Jan 4, 2023
  2. ghost changed the title [-]INIT_OVERLOADED_CLASS_ENTRY uses sizeof() to determine class name length[/-] [+]INIT_CLASS_ENTRY uses sizeof() to determine class name length[/+] on Jan 4, 2023
  3. cmb69 commented on Jan 4, 2023

    @cmb69
    Member

    I don't understand why this would be a bug. Are you writing a PHP extension? If so, you can use INIT_CLASS_ENTRY_EX() in the first place, if you are not passing a constant as class.

  4. cmb69 commented on Jan 4, 2023

    @cmb69
    Member

    these are all required to compile on multiple versions of PHP (5.4->8.0)

    Ugh, that's a tough requirement.

    Anyhow, I think we can change INIT_OVERLOADED_CLASS_ENTRY and maybe some others to no longer use sizeof, but rather strlen() instead, but not everybody may like that (see #8336).

  5. Girgias commented on Jan 4, 2023

    @Girgias
    Member

    these are all required to compile on multiple versions of PHP (5.4->8.0)

    Ugh, that's a tough requirement.

    Anyhow, I think we can change INIT_OVERLOADED_CLASS_ENTRY and maybe some others to no longer use sizeof, but rather strlen() instead, but not everybody may like that (see #8336).

    I think for stuff like this which may be used by extensions it makes sense to proceed with those changes compared to changing all possible instances within bundled extensions

  6. cmb69 commented on Jan 5, 2023

    @cmb69
    Member

    @dbuteyn, maybe you want to provide a respective PR?

  7. cmb69 commented on Jan 5, 2023

    @cmb69
    Member

    Yeah, I don't think sizeof has been used for any other purpose than having the optimization (old compilers may not have optimized strlen()).

  8. changed the title [-]INIT_CLASS_ENTRY uses sizeof() to determine class name length[/-] [+]INIT_CLASS_ENTRY should use strlen() to determine class name length[/+] on Jan 5, 2023
  9. added a commit that references this issue on Jul 8, 2026
    d0e3919
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions