File tree 1 file changed +9
-3
lines changed
1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -302,9 +302,15 @@ PHP_FUNCTION(socket_cmsg_space)
302
302
return ;
303
303
}
304
304
305
- if (entry -> var_el_size > 0 && n > (zend_long )((ZEND_LONG_MAX - entry -> size -
306
- CMSG_SPACE (0 ) - 15L ) / entry -> var_el_size )) {
307
- /* the -15 is to account for any padding CMSG_SPACE may add after the data */
305
+ size_t rem_size = ZEND_LONG_MAX - entry -> size ;
306
+ size_t n_max = entry -> var_el_size > 0 ? rem_size / entry -> var_el_size : 0 ;
307
+ size_t size = entry -> size + n * entry -> var_el_size ;
308
+ size_t total_size = CMSG_SPACE (size );
309
+
310
+ if (entry -> var_el_size > 0
311
+ && (n > n_max /* zend_long overflow */
312
+ || total_size > ZEND_LONG_MAX
313
+ || total_size < size /* align overflow */ )) {
308
314
php_error_docref (NULL , E_WARNING , "The value for the "
309
315
"third argument (" ZEND_LONG_FMT ") is too large" , n );
310
316
return ;
You can’t perform that action at this time.
0 commit comments