Skip to content
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

Segmentation fault in mhash() #16711

Closed
YuanchengJiang opened this issue Nov 6, 2024 · 1 comment
Closed

Segmentation fault in mhash() #16711

YuanchengJiang opened this issue Nov 6, 2024 · 1 comment

Comments

@YuanchengJiang
Copy link

Description

The following code:

<?php
mhash(133, 1086849124, 133);

Resulted in this output:

/php-src/Zend/zend_operators.c:3064:18: runtime error: member access within null pointer of type 'zend_string' (aka 'struct _zend_string')

PHP Version

nightly

Operating System

No response

@Girgias
Copy link
Member

Girgias commented Nov 6, 2024

Found the root cause: The algorithm 133 does not exist, thus algo is a nullptr which gets passed to php_hash_do_hash_hmac() which queries the php_hash_op via php_hash_fetch_ops() which assumes the zend_string is never null.

Same issue exists with php_hash_do_hash().

This does not happen with the hash_* variant, as they take strings as algo inputs rather than an int.

Girgias added a commit to Girgias/php-src that referenced this issue Nov 6, 2024
@Girgias Girgias linked a pull request Nov 6, 2024 that will close this issue
Girgias added a commit to Girgias/php-src that referenced this issue Nov 6, 2024
Girgias added a commit to Girgias/php-src that referenced this issue Nov 6, 2024
Girgias added a commit to Girgias/php-src that referenced this issue Nov 6, 2024
Girgias added a commit that referenced this issue Nov 10, 2024
* PHP-8.2:
  ext/hash: Fix GH-16711: Segfault in mhash()
  ext/hash: Add failing tests for GH-16711
Girgias added a commit that referenced this issue Nov 10, 2024
* PHP-8.3:
  ext/hash: Fix GH-16711: Segfault in mhash()
  ext/hash: Add failing tests for GH-16711
Girgias added a commit that referenced this issue Nov 10, 2024
* PHP-8.4:
  ext/hash: Fix GH-16711: Segfault in mhash()
  ext/hash: Add failing tests for GH-16711
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants