@@ -545,8 +545,9 @@ PHP_REDIS_API int redis_subscribe_response(INTERNAL_FUNCTION_PARAMETERS,
545545 /* Multibulk response, {[pattern], type, channel, payload } */
546546 while (redis_sock -> subs [i ]) {
547547 zval z_ret , z_args [4 ], * z_type , * z_chan , * z_pat = NULL , * z_data ;
548- HashTable * ht_tab ;
549548 int tab_idx = 1 , is_pmsg = 0 ;
549+ HashTable * ht_tab ;
550+ zend_string * zs ;
550551
551552 ZVAL_NULL (& z_resp );
552553 if (!redis_sock_read_multibulk_reply_zval (redis_sock , & z_resp )) {
@@ -573,22 +574,26 @@ PHP_REDIS_API int redis_subscribe_response(INTERNAL_FUNCTION_PARAMETERS,
573574 }
574575
575576 // Extract pattern if it's a pmessage
576- if (is_pmsg ) {
577- if ((z_pat = zend_hash_index_find (ht_tab , tab_idx ++ )) == NULL ) {
577+ if (is_pmsg ) {
578+ z_pat = zend_hash_index_find (ht_tab , tab_idx ++ );
579+ if (z_pat == NULL || Z_TYPE_P (z_pat ) != IS_STRING )
578580 goto failure ;
579- }
580581 }
581582
582- // Extract channel and data
583- if ((z_chan = zend_hash_index_find (ht_tab , tab_idx ++ )) == NULL ||
584- (z_data = zend_hash_index_find (ht_tab , tab_idx ++ )) == NULL
585- ) {
583+ /* Extract channel */
584+ z_chan = zend_hash_index_find (ht_tab , tab_idx ++ );
585+ if (z_chan == NULL || Z_TYPE_P (z_chan ) != IS_STRING )
586586 goto failure ;
587- }
588587
589- if ((cb = zend_hash_str_find_ptr (redis_sock -> subs [i ], Z_STRVAL_P (z_chan ), Z_STRLEN_P (z_chan ))) == NULL ) {
588+ /* Finally, extract data */
589+ z_data = zend_hash_index_find (ht_tab , tab_idx ++ );
590+ if (z_data == NULL )
591+ goto failure ;
592+
593+ /* Find our callback, either by channel or pattern string */
594+ zs = z_pat != NULL ? Z_STR_P (z_pat ) : Z_STR_P (z_chan );
595+ if ((cb = zend_hash_find_ptr (redis_sock -> subs [i ], zs )) == NULL )
590596 goto failure ;
591- }
592597
593598 // Different args for SUBSCRIBE and PSUBSCRIBE
594599 z_args [0 ] = * getThis ();
0 commit comments