# Hash problems in session-oo code

- Thread: https://externals.io/message/56265
- Original archive: https://news-web.php.net/php.internals/56265
- Started by Rasmus Lerdorf on 2011-11-11T00:17:10+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #56265 — Rasmus Lerdorf — 2011-11-11T00:17:10+00:00

URL: https://externals.io/message/56265#56265

Hey Arpad, looking through the code you added to
ext/standard/basic_functions.c it looks like you are doing some weird
key handling in the shutdown function hash.

In register_user_shutdown_function() you have:

zend_hash_update(BG(user_shutdown_function_names), function_name,
sizeof(function_name), shutdown_function_entry,
sizeof(php_shutdown_function_entry), NULL)

And in remove_user_shutdown_function() you have:

zend_hash_del_key_or_index(BG(user_shutdown_function_names),
function_name, sizeof(function_name), 0, HASH_DEL_KEY)

In both cases function_name is a char* so sizeof(function_name) is
always going to be the size of a char* on whatever architecture you are
on. But the way hash keys work, it is the actual string that is the key
and you should be passing the length of that string here.

-Rasmus

---

## #56278 — Arpad Ray — 2011-11-11T14:45:32+00:00

URL: https://externals.io/message/56265#56278 · In reply to: #56265

> Hey Arpad, looking through the code you added to
> ext/standard/basic_functions.c it looks like you are doing some weird
> key handling in the shutdown function hash.
>
>
Hi Rasmus,

Thanks for the heads up, just fixed these.

Cheers,

Arpad



> In register_user_shutdown_function() you have:
>
> zend_hash_update(BG(user_shutdown_function_names), function_name,
> sizeof(function_name), shutdown_function_entry,
> sizeof(php_shutdown_function_entry), NULL)
>
> And in remove_user_shutdown_function() you have:
>
> zend_hash_del_key_or_index(BG(user_shutdown_function_names),
> function_name, sizeof(function_name), 0, HASH_DEL_KEY)
>
> In both cases function_name is a char* so sizeof(function_name) is
> always going to be the size of a char* on whatever architecture you are
> on. But the way hash keys work, it is the actual string that is the key
> and you should be passing the length of that string here.
>
> -Rasmus
