while (optionEnd > option)
{
- switch (option[0])
- {
- case TCPOPT_EOL:
- option = optionEnd;
+ /* Bounds checking to avoid infinite loops */
+ if (option[0] == TCPOPT_EOL)
+ break;
+
+ if (option[0] == TCPOPT_NOP) {
+ ++option;
+ continue;
+ } else {
+ if (optionEnd - option < 2)
break;
-
- case TCPOPT_NOP:
- ++option;
+ if (option[1] < 2 || option + option[1] >= optionEnd)
break;
+ }
+ switch (option[0])
+ {
case TCPOPT_MAXSEG:
if (option[1] == 4)
{
if (packetAliasMSS < mssVal)
{
int accumulate = mssVal;
- int accnetorder = 0 ;
+ int accnetorder = 0 ;
+
accumulate -= packetAliasMSS;
*mssPtr = htons(packetAliasMSS);
- accnetorder = htons(accumulate);
+ accnetorder = htons(accumulate);
ADJUST_CHECKSUM(accnetorder, tc->th_sum);
}