Skip to content

Commit 2020159

Browse files
committed
zero the window manually, to catch undefined behaviour
1 parent 89d5cbc commit 2020159

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

api/oc_replay.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,13 @@ oc_replay_check_client(uint64_t rx_ssn, oc_string_t rx_kid,
187187
// slide the window and accept the packet
188188
rec->rx_ssn = rx_ssn;
189189
// ssn_diff is negative in this side of the if
190-
rec->window = rec->window << (-ssn_diff);
190+
// note that shifting by an amount greater than the size of the type
191+
// is undefined behaviour, so we must zero the window manually here
192+
if (-ssn_diff >= sizeof(rec->window) * 8)
193+
rec->window = 0;
194+
else
195+
rec->window = rec->window << (-ssn_diff);
196+
191197
// set bit 1, indicating ssn rec->rx_ssn has been received
192198
rec->window |= 1;
193199
return true;

0 commit comments

Comments
 (0)