PHP 4.0.3 patches - MM
| From: | (Mikhail Zabaluev) | Date: | Fri, 03 Nov 2000 06:35:57 +0000 |
| Subject: | PHP 4.0.3 patches - MM | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-36910@lists.php.net to get a copy of this message | ||
The second patch prevents a crash when MM initialization fails, for
example, when the session lockfile cannot be opened. The patch also fixes
an awful glitch in the hash function (-HIGH_BITS == 0x10000000 on
32-bit machines).
--
Hope this helps,
MhZ mailto:mookid@sigent.ru
-----------
Today's weirdness is tomorrow's reason why.
-- Hunter S. Thompson
--- ext/session/mod_mm.c~ Sat Oct 28 01:10:31 2000 +++ ext/session/mod_mm.c Thu Nov 2 20:17:46 2000 @@ -77,7 +77,7 @@ for (val = 0; *data; data++) { val = (val << ONE_EIGTH) + *data; if ((i = val & HIGH_BITS) != 0) - val = (val ^ (i >> THREE_QUARTERS)) & -HIGH_BITS; + val = val ^ (i >> THREE_QUARTERS) ^ i; } return val; @@ -176,8 +176,15 @@ static int ps_mm_initialize(ps_mm *data, const char *path) { data->mm = mm_create(0, path); + if (!data->mm) { + return FAILURE; + } data->hash = mm_calloc(data->mm, HASH_SIZE, sizeof(*data->hash)); + if (!data->hash) { + mm_destroy(data->mm); + return FAILURE; + } return SUCCESS; } @@ -200,15 +207,21 @@ PHP_GINIT_FUNCTION(ps_mm) { ps_mm_instance = calloc(sizeof(*ps_mm_instance), 1); - ps_mm_initialize(ps_mm_instance, PS_MM_PATH); + if (ps_mm_initialize(ps_mm_instance, PS_MM_PATH) != SUCCESS) { + ps_mm_instance = NULL; + return FAILURE; + } return SUCCESS; } PHP_GSHUTDOWN_FUNCTION(ps_mm) { - ps_mm_destroy(ps_mm_instance); - free(ps_mm_instance); - return SUCCESS; + if (ps_mm_instance) { + ps_mm_destroy(ps_mm_instance); + free(ps_mm_instance); + return SUCCESS; + } + return FAILURE; } PS_OPEN_FUNC(mm)
--- ext/session/mod_mm.c~ Sat Oct 28 01:10:31 2000 +++ ext/session/mod_mm.c Thu Nov 2 20:17:46 2000 @@ -77,7 +77,7 @@ for (val = 0; *data; data++) { val = (val << ONE_EIGTH) + *data; if ((i = val & HIGH_BITS) != 0) - val = (val ^ (i >> THREE_QUARTERS)) & -HIGH_BITS; + val = val ^ (i >> THREE_QUARTERS) ^ i; } return val; @@ -176,8 +176,15 @@ static int ps_mm_initialize(ps_mm *data, const char *path) { data->mm = mm_create(0, path); + if (!data->mm) { + return FAILURE; + } data->hash = mm_calloc(data->mm, HASH_SIZE, sizeof(*data->hash)); + if (!data->hash) { + mm_destroy(data->mm); + return FAILURE; + } return SUCCESS; } @@ -200,15 +207,21 @@ PHP_GINIT_FUNCTION(ps_mm) { ps_mm_instance = calloc(sizeof(*ps_mm_instance), 1); - ps_mm_initialize(ps_mm_instance, PS_MM_PATH); + if (ps_mm_initialize(ps_mm_instance, PS_MM_PATH) != SUCCESS) { + ps_mm_instance = NULL; + return FAILURE; + } return SUCCESS; } PHP_GSHUTDOWN_FUNCTION(ps_mm) { - ps_mm_destroy(ps_mm_instance); - free(ps_mm_instance); - return SUCCESS; + if (ps_mm_instance) { + ps_mm_destroy(ps_mm_instance); + free(ps_mm_instance); + return SUCCESS; + } + return FAILURE; } PS_OPEN_FUNC(mm)