@@ -351,8 +351,21 @@ static void _php_db2_set_symbol(char * varname, zval *var)
351351}
352352/* }}} */
353353
354+ /* {{{ Murmur hash implementation (for persistent key hash)
355+ */
354356
357+ static unsigned int _php_db2_MurmurOAAT32 (const char * key )
358+ {
359+ unsigned int h = 3323198485 ;
360+ for (;* key ;++ key ) {
361+ h ^= * key ;
362+ h *= 0x5bd1e995 ;
363+ h ^= h >> 15 ;
364+ }
365+ return h ;
366+ }
355367
368+ /* }}} */
356369
357370#ifdef PASE /* IBM i meta change ""->NULL */
358371static void _php_db2_meta_helper (SQLCHAR * * qualifier , size_t * qualifier_len ,
@@ -2313,6 +2326,7 @@ static int _php_db2_connect_helper( INTERNAL_FUNCTION_PARAMETERS, conn_handle **
23132326 int reused = 0 ;
23142327 int hKeyLen = 0 ;
23152328 char * hKey = NULL ;
2329+ unsigned int password_hashed ;
23162330 char server [2048 ];
23172331 int attr = SQL_TRUE ;
23182332 size_t database_len ;
@@ -2354,10 +2368,13 @@ static int _php_db2_connect_helper( INTERNAL_FUNCTION_PARAMETERS, conn_handle **
23542368 /* Check if we already have a connection for this userID & database combination */
23552369 if (isPersistent ) {
23562370 zend_resource * entry ;
2357- hKeyLen = strlen (database ) + strlen (uid ) + 8 ;
2371+ hKeyLen = strlen (database ) + strlen (uid ) +
2372+ sizeof ("__db2_..FFFFFFFF" ); /* constant part; includes null */
23582373 hKey = (char * ) ecalloc (1 , hKeyLen );
23592374
2360- sprintf (hKey , "__db2_%s.%s" , uid , database );
2375+ /* XXX: How do we include the options (array) in here too? */
2376+ password_hashed = _php_db2_MurmurOAAT32 (password );
2377+ snprintf (hKey , hKeyLen , "__db2_%s.%s.%08x" , uid , database , password_hashed );
23612378 temp = zend_hash_str_find_ptr (& EG (persistent_list ), hKey , hKeyLen );
23622379 if ( temp && temp -> type == le_pconn_struct ) {
23632380 conn_res = * pconn_res = (conn_handle * )temp -> ptr ;
0 commit comments