Skip to content

Commit

Permalink
Create persistent interned string for password algos
Browse files Browse the repository at this point in the history
These strings are returned to userland by password_algos(),
which violates thread-safety invariants. Create persistent
interned strings for them instead.
  • Loading branch information
nikic committed Jul 20, 2021
1 parent 051ff33 commit b0d4d6e
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions ext/standard/password.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,8 @@
static zend_array php_password_algos;

int php_password_algo_register(const char *ident, const php_password_algo *algo) {
zval zalgo;
ZVAL_PTR(&zalgo, (php_password_algo*)algo);
if (zend_hash_str_add(&php_password_algos, ident, strlen(ident), &zalgo)) {
return SUCCESS;
}
return FAILURE;
zend_string *key = zend_string_init_interned(ident, strlen(ident), 1);
return zend_hash_add_ptr(&php_password_algos, key, (void *) algo) ? SUCCESS : FAILURE;
}

void php_password_algo_unregister(const char *ident) {
Expand Down

0 comments on commit b0d4d6e

Please sign in to comment.