@@ -126,10 +126,17 @@ PHP_FUNCTION(shm_attach)
126126 sysvshm_shm * shm_list_ptr ;
127127 char * shm_ptr ;
128128 sysvshm_chunk_head * chunk_ptr ;
129- zend_long shm_key , shm_id , shm_size , shm_flag = 0666 ;
129+ zend_long shm_key_arg , shm_id , shm_size , shm_flag = 0666 ;
130+ key_t shm_key ;
130131 bool shm_size_is_null = true;
131132
132- if (SUCCESS != zend_parse_parameters (ZEND_NUM_ARGS (), "l|l!l" , & shm_key , & shm_size , & shm_size_is_null , & shm_flag )) {
133+ if (SUCCESS != zend_parse_parameters (ZEND_NUM_ARGS (), "l|l!l" , & shm_key_arg , & shm_size , & shm_size_is_null , & shm_flag )) {
134+ RETURN_THROWS ();
135+ }
136+
137+ shm_key = (key_t ) shm_key_arg ;
138+ if ((zend_long ) shm_key != shm_key_arg ) {
139+ zend_argument_value_error (1 , "is out of range" );
133140 RETURN_THROWS ();
134141 }
135142
@@ -145,17 +152,17 @@ PHP_FUNCTION(shm_attach)
145152 /* get the id from a specified key or create new shared memory */
146153 if ((shm_id = shmget (shm_key , 0 , 0 )) < 0 ) {
147154 if (shm_size < (zend_long )sizeof (sysvshm_chunk_head )) {
148- php_error_docref (NULL , E_WARNING , "Failed for key 0x" ZEND_XLONG_FMT ": memorysize too small" , shm_key );
155+ php_error_docref (NULL , E_WARNING , "Failed for key 0x" ZEND_XLONG_FMT ": memorysize too small" , shm_key_arg );
149156 RETURN_FALSE ;
150157 }
151158 if ((shm_id = shmget (shm_key , shm_size , shm_flag | IPC_CREAT | IPC_EXCL )) < 0 ) {
152- php_error_docref (NULL , E_WARNING , "Failed for key 0x" ZEND_XLONG_FMT ": %s" , shm_key , strerror (errno ));
159+ php_error_docref (NULL , E_WARNING , "Failed for key 0x" ZEND_XLONG_FMT ": %s" , shm_key_arg , strerror (errno ));
153160 RETURN_FALSE ;
154161 }
155162 }
156163
157164 if ((shm_ptr = shmat (shm_id , NULL , 0 )) == (void * ) -1 ) {
158- php_error_docref (NULL , E_WARNING , "Failed for key 0x" ZEND_XLONG_FMT ": %s" , shm_key , strerror (errno ));
165+ php_error_docref (NULL , E_WARNING , "Failed for key 0x" ZEND_XLONG_FMT ": %s" , shm_key_arg , strerror (errno ));
159166 RETURN_FALSE ;
160167 }
161168
0 commit comments