@ -150,9 +150,9 @@ DecodeIPV6ExtHdrs(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt
SCEnter ( ) ;
SCEnter ( ) ;
uint8_t * orig_pkt = pkt ;
uint8_t * orig_pkt = pkt ;
uint8_t nh = 0 ; /* careful, 0 is actually a real type */
uint8_t nh = IPV6_GET_NH ( p ) ; /* careful, 0 is actually a real type */
uint16_t hdrextlen = 0 ;
uint16_t hdrextlen = 0 ;
uint16_t plen ;
uint16_t plen = len ;
char dstopts = 0 ;
char dstopts = 0 ;
char exthdr_fh_done = 0 ;
char exthdr_fh_done = 0 ;
int hh = 0 ;
int hh = 0 ;
@ -160,18 +160,18 @@ DecodeIPV6ExtHdrs(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt
int eh = 0 ;
int eh = 0 ;
int ah = 0 ;
int ah = 0 ;
nh = IPV6_GET_NH ( p ) ;
plen = len ;
while ( 1 )
while ( 1 )
{
{
/* No upper layer, but we do have data. Suspicious. */
if ( nh = = IPPROTO_NONE ) {
if ( nh = = IPPROTO_NONE & & plen > 0 ) {
if ( plen > 0 ) {
ENGINE_SET_EVENT ( p , IPV6_DATA_AFTER_NONE_HEADER ) ;
/* No upper layer, but we do have data. Suspicious. */
ENGINE_SET_EVENT ( p , IPV6_DATA_AFTER_NONE_HEADER ) ;
}
SCReturn ;
SCReturn ;
}
}
if ( plen < 2 ) { /* minimal needed in a hdr */
if ( plen < 2 ) { /* minimal needed in a hdr */
ENGINE_SET_INVALID_EVENT ( p , IPV6_TRUNC_EXTHDR ) ;
SCReturn ;
SCReturn ;
}
}
@ -204,7 +204,7 @@ DecodeIPV6ExtHdrs(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt
SCLogDebug ( " hdrextlen % " PRIu8 , hdrextlen ) ;
SCLogDebug ( " hdrextlen % " PRIu8 , hdrextlen ) ;
if ( hdrextlen > plen ) {
if ( hdrextlen > plen ) {
ENGINE_SET_ EVENT( p , IPV6_TRUNC_EXTHDR ) ;
ENGINE_SET_ INVALID_ EVENT( p , IPV6_TRUNC_EXTHDR ) ;
SCReturn ;
SCReturn ;
}
}
@ -243,7 +243,7 @@ DecodeIPV6ExtHdrs(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt
IPV6_SET_L4PROTO ( p , nh ) ;
IPV6_SET_L4PROTO ( p , nh ) ;
hdrextlen = ( * ( pkt + 1 ) + 1 ) < < 3 ;
hdrextlen = ( * ( pkt + 1 ) + 1 ) < < 3 ;
if ( hdrextlen > plen ) {
if ( hdrextlen > plen ) {
ENGINE_SET_ EVENT( p , IPV6_TRUNC_EXTHDR ) ;
ENGINE_SET_ INVALID_ EVENT( p , IPV6_TRUNC_EXTHDR ) ;
SCReturn ;
SCReturn ;
}
}
@ -288,7 +288,7 @@ DecodeIPV6ExtHdrs(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt
if ( optslen > plen ) {
if ( optslen > plen ) {
/* since the packet is long enough (we checked
/* since the packet is long enough (we checked
* plen against hdrlen , the optlen must be malformed . */
* plen against hdrlen , the optlen must be malformed . */
ENGINE_SET_ EVENT( p , IPV6_EXTHDR_INVALID_OPTLEN ) ;
ENGINE_SET_ INVALID_ EVENT( p , IPV6_EXTHDR_INVALID_OPTLEN ) ;
/* skip past this extension so we can continue parsing the rest
/* skip past this extension so we can continue parsing the rest
* of the packet */
* of the packet */
nh = * pkt ;
nh = * pkt ;
@ -311,7 +311,7 @@ DecodeIPV6ExtHdrs(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt
}
}
if ( offset + 1 > = optslen ) {
if ( offset + 1 > = optslen ) {
ENGINE_SET_ EVENT( p , IPV6_EXTHDR_INVALID_OPTLEN ) ;
ENGINE_SET_ INVALID_ EVENT( p , IPV6_EXTHDR_INVALID_OPTLEN ) ;
break ;
break ;
}
}
@ -320,7 +320,7 @@ DecodeIPV6ExtHdrs(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt
/* see if the optlen from the packet fits the total optslen */
/* see if the optlen from the packet fits the total optslen */
if ( ( offset + 1 + ip6_optlen ) > optslen ) {
if ( ( offset + 1 + ip6_optlen ) > optslen ) {
ENGINE_SET_ EVENT( p , IPV6_EXTHDR_INVALID_OPTLEN ) ;
ENGINE_SET_ INVALID_ EVENT( p , IPV6_EXTHDR_INVALID_OPTLEN ) ;
break ;
break ;
}
}
@ -339,7 +339,7 @@ DecodeIPV6ExtHdrs(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt
ra - > ip6ra_len = ip6_optlen ;
ra - > ip6ra_len = ip6_optlen ;
if ( ip6_optlen < sizeof ( ra - > ip6ra_value ) ) {
if ( ip6_optlen < sizeof ( ra - > ip6ra_value ) ) {
ENGINE_SET_ EVENT( p , IPV6_EXTHDR_INVALID_OPTLEN ) ;
ENGINE_SET_ INVALID_ EVENT( p , IPV6_EXTHDR_INVALID_OPTLEN ) ;
break ;
break ;
}
}
@ -355,7 +355,7 @@ DecodeIPV6ExtHdrs(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt
jumbo - > ip6j_len = ip6_optlen ;
jumbo - > ip6j_len = ip6_optlen ;
if ( ip6_optlen < sizeof ( jumbo - > ip6j_payload_len ) ) {
if ( ip6_optlen < sizeof ( jumbo - > ip6j_payload_len ) ) {
ENGINE_SET_ EVENT( p , IPV6_EXTHDR_INVALID_OPTLEN ) ;
ENGINE_SET_ INVALID_ EVENT( p , IPV6_EXTHDR_INVALID_OPTLEN ) ;
break ;
break ;
}
}
@ -370,7 +370,7 @@ DecodeIPV6ExtHdrs(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt
hao - > ip6hao_len = ip6_optlen ;
hao - > ip6hao_len = ip6_optlen ;
if ( ip6_optlen < sizeof ( hao - > ip6hao_hoa ) ) {
if ( ip6_optlen < sizeof ( hao - > ip6hao_hoa ) ) {
ENGINE_SET_ EVENT( p , IPV6_EXTHDR_INVALID_OPTLEN ) ;
ENGINE_SET_ INVALID_ EVENT( p , IPV6_EXTHDR_INVALID_OPTLEN ) ;
break ;
break ;
}
}
@ -422,7 +422,7 @@ DecodeIPV6ExtHdrs(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt
uint16_t prev_hdrextlen = hdrextlen ;
uint16_t prev_hdrextlen = hdrextlen ;
hdrextlen = sizeof ( IPV6FragHdr ) ;
hdrextlen = sizeof ( IPV6FragHdr ) ;
if ( hdrextlen > plen ) {
if ( hdrextlen > plen ) {
ENGINE_SET_ EVENT( p , IPV6_TRUNC_EXTHDR ) ;
ENGINE_SET_ INVALID_ EVENT( p , IPV6_TRUNC_EXTHDR ) ;
SCReturn ;
SCReturn ;
}
}
@ -468,7 +468,7 @@ DecodeIPV6ExtHdrs(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt
IPV6_SET_L4PROTO ( p , nh ) ;
IPV6_SET_L4PROTO ( p , nh ) ;
hdrextlen = sizeof ( IPV6EspHdr ) ;
hdrextlen = sizeof ( IPV6EspHdr ) ;
if ( hdrextlen > plen ) {
if ( hdrextlen > plen ) {
ENGINE_SET_ EVENT( p , IPV6_TRUNC_EXTHDR ) ;
ENGINE_SET_ INVALID_ EVENT( p , IPV6_TRUNC_EXTHDR ) ;
SCReturn ;
SCReturn ;
}
}
@ -497,7 +497,7 @@ DecodeIPV6ExtHdrs(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt
SCLogDebug ( " hdrextlen % " PRIu8 , hdrextlen ) ;
SCLogDebug ( " hdrextlen % " PRIu8 , hdrextlen ) ;
if ( hdrextlen > plen ) {
if ( hdrextlen > plen ) {
ENGINE_SET_ EVENT( p , IPV6_TRUNC_EXTHDR ) ;
ENGINE_SET_ INVALID_ EVENT( p , IPV6_TRUNC_EXTHDR ) ;
SCReturn ;
SCReturn ;
}
}
@ -538,7 +538,7 @@ DecodeIPV6ExtHdrs(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt
case IPPROTO_SHIM6 :
case IPPROTO_SHIM6 :
hdrextlen = 8 + ( * ( pkt + 1 ) * 8 ) ; /* 8 bytes + length in 8 octet units */
hdrextlen = 8 + ( * ( pkt + 1 ) * 8 ) ; /* 8 bytes + length in 8 octet units */
if ( hdrextlen > plen ) {
if ( hdrextlen > plen ) {
ENGINE_SET_ EVENT( p , IPV6_TRUNC_EXTHDR ) ;
ENGINE_SET_ INVALID_ EVENT( p , IPV6_TRUNC_EXTHDR ) ;
SCReturn ;
SCReturn ;
}
}
nh = * pkt ;
nh = * pkt ;