Skip to content

Commit

Permalink
decode/pppoe: skip useless loop unless debug
Browse files Browse the repository at this point in the history
Looping over tags has no effects, except debug logging
  • Loading branch information
catenacyber committed Mar 11, 2024
1 parent d2db8bf commit 59d18b9
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/decode-pppoe.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,6 @@ int DecodePPPOEDiscovery(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p,
return TM_ECODE_OK;
}

/* parse any tags we have in the packet */

uint32_t tag_length = 0;
const uint8_t* pkt_pppoedt = pkt + PPPOE_DISCOVERY_HEADER_MIN_LEN;

uint32_t pppoe_length = SCNtohs(p->pppoedh->pppoe_length);
uint32_t packet_length = len - PPPOE_DISCOVERY_HEADER_MIN_LEN ;

Expand All @@ -97,13 +92,16 @@ int DecodePPPOEDiscovery(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p,
return TM_ECODE_OK;
}

// packet_length >= pppoe_length so we have enough data
while (pppoe_length >= sizeof(PPPOEDiscoveryTag))
{
PPPOEDiscoveryTag* pppoedt = (PPPOEDiscoveryTag*)pkt_pppoedt;
#ifdef DEBUG
/* parse any tags we have in the packet */

uint32_t tag_length = 0;
const uint8_t *pkt_pppoedt = pkt + PPPOE_DISCOVERY_HEADER_MIN_LEN;

// packet_length >= pppoe_length so we have enough data
while (pppoe_length >= sizeof(PPPOEDiscoveryTag)) {
PPPOEDiscoveryTag *pppoedt = (PPPOEDiscoveryTag *)pkt_pppoedt;
uint16_t tag_type = SCNtohs(pppoedt->pppoe_tag_type);
#endif
// upgrade to u32 to avoid u16 overflow
tag_length = SCNtohs(pppoedt->pppoe_tag_length);

Expand All @@ -116,6 +114,7 @@ int DecodePPPOEDiscovery(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p,
pppoe_length = 0; // don't want an underflow
}
}
#endif

return TM_ECODE_OK;
}
Expand Down

0 comments on commit 59d18b9

Please sign in to comment.