Skip to content

Commit aee532f

Browse files
committed
ext/openssl: Reorder reneg rate-limit decay to avoid integer divide to zero
php_openssl_limit_handshake_reneg() computes the bucket decay as elapsed * (limit / window). Both operands are zend_long, so with the documented defaults limit=2 and window=300 the inner division truncates to 0 and the decay term collapses to 0 for every elapsed value. The leaky bucket stops leaking and the cap fires after exactly limit renegotiations regardless of how widely spaced in time, not "limit per window seconds" as documented. Compute the decay in double-precision floating point so user-controlled reneg_limit and reneg_window values cannot trigger signed integer overflow in elapsed_time * limit. Guard against window <= 0 to keep the divide well-defined under values the existing init handler does not validate.
1 parent 05afc37 commit aee532f

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

ext/openssl/xp_ssl.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1131,7 +1131,9 @@ static void php_openssl_limit_handshake_reneg(const SSL *ssl) /* {{{ */
11311131

11321132
elapsed_time = (now.tv_sec - sslsock->reneg->prev_handshake);
11331133
sslsock->reneg->prev_handshake = now.tv_sec;
1134-
sslsock->reneg->tokens -= (elapsed_time * (sslsock->reneg->limit / sslsock->reneg->window));
1134+
if (sslsock->reneg->window > 0) {
1135+
sslsock->reneg->tokens -= ((double)elapsed_time * (double)sslsock->reneg->limit) / (double)sslsock->reneg->window;
1136+
}
11351137

11361138
if (sslsock->reneg->tokens < 0) {
11371139
sslsock->reneg->tokens = 0;

0 commit comments

Comments
 (0)