Avoid overflow of spdylay_stream.recv_window_size

This commit is contained in:
Tatsuhiro Tsujikawa 2012-05-20 16:13:26 +09:00
parent b95e9a8c4c
commit 6f066d7f64
1 changed files with 8 additions and 4 deletions

View File

@ -2360,11 +2360,15 @@ static int spdylay_session_update_recv_window_size(spdylay_session *session,
spdylay_stream *stream; spdylay_stream *stream;
stream = spdylay_session_get_stream(session, stream_id); stream = spdylay_session_get_stream(session, stream_id);
if(stream) { if(stream) {
/* TODO If SPDYLAY_OPT_NO_AUTO_WINDOW_UPDATE is set and the /* If SPDYLAY_OPT_NO_AUTO_WINDOW_UPDATE is set and the application
application does not send WINDOW_UPDATE and the remote endpoint does not send WINDOW_UPDATE and the remote endpoint keeps
keeps sending data, stream->recv_window_size will eventually sending data, stream->recv_window_size will eventually
overflow. */ overflow. */
stream->recv_window_size += delta_size; if(stream->recv_window_size > INT32_MAX - delta_size) {
stream->recv_window_size = INT32_MAX;
} else {
stream->recv_window_size += delta_size;
}
if(!(session->opt_flags & SPDYLAY_OPTMASK_NO_AUTO_WINDOW_UPDATE)) { if(!(session->opt_flags & SPDYLAY_OPTMASK_NO_AUTO_WINDOW_UPDATE)) {
/* This is just a heuristics. */ /* This is just a heuristics. */
/* We have to use local_settings here because it is the constraint /* We have to use local_settings here because it is the constraint