Skip to content

Conversation

@crrodriguez
Copy link
Contributor

gcc12 complains:

zend_API.c:2782:49: warning: array subscript ‘zend_function {aka union _zend_function}[0]’ is partly outside array bounds of ‘unsigned char[120]’ [-Warray-bounds]
zend_API.c:2772:32: note: object of size 120 allocated by ‘malloc’
reg_function = malloc(sizeof(zend_internal_function));

The warning is correct, reg_function allocation size is too small for its type,
allocate sizeof(zend_function) instead.

gcc12 complains:

zend_API.c:2782:49: warning: array subscript ‘zend_function {aka union _zend_function}[0]’ is partly outside array bounds of ‘unsigned char[120]’ [-Warray-bounds]
zend_API.c:2772:32: note: object of size 120 allocated by ‘malloc’
reg_function = malloc(sizeof(zend_internal_function));

The warning is correct, reg_function allocation size is too small for its type,
allocate sizeof(zend_function) instead.
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.

Ah yeah, this looks right, thank you! Shouldn't this be fixed for PHP-8.0+, though?

lowercase_name = zend_new_interned_string(lowercase_name);
reg_function = malloc(sizeof(zend_internal_function));
memcpy(reg_function, &function, sizeof(zend_internal_function));
reg_function = calloc(1, sizeof(zend_function));
Copy link
Member

Choose a reason for hiding this comment

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

That calloc() appears unnecessary, since we're overwriting the memory in the next statement anyway.

@bwoebi
Copy link
Member

bwoebi commented May 2, 2022

@cmb69 the allocation has the right size, but technically the proper target is &reg_function->internal_function to assign to instead of reg_function. (we're allocating an internal function, not an op_array)
(i.e. it's "just" a compiler warning, which does not have a deep view into that union and does not know that reg_function->op_array is not allowed)

@cmb69
Copy link
Member

cmb69 commented May 2, 2022

Holy hack, Batman! I see that this is not a bug in php-src.

But if we always treat reg_function as internal function, why not declare and use it as such?

@bwoebi
Copy link
Member

bwoebi commented May 2, 2022

I suppose to avoid a couple explicit casts back to zend_function * when passing reg_function around to some calls?

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.

According to the discussion so far, this doesn't look like the proper fix. Either there is a simple way to avoid the compiler warning, or maybe we should see how changing reg_function to be of type zend_internal_function may work out.

@github-actions
Copy link

There has not been any recent activity in this PR. It will automatically be closed in 7 days if no further action is taken.

@github-actions github-actions bot added the Stale label Jul 22, 2022
@github-actions github-actions bot closed this Jul 30, 2022
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.

4 participants