Skip to content

Commit 95017a4

Browse files
authored
Merge pull request #96 from YanzhaoLi/topic/modify-parse-tcphdr
Consider variable TCP header size when parse_tcphdr
2 parents 7403d11 + f288060 commit 95017a4

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

common/parsing_helpers.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ static __always_inline int parse_iphdr(struct hdr_cursor *nh,
139139
return -1;
140140

141141
hdrsize = iph->ihl * 4;
142+
/* Sanity check packet field is valid */
143+
if(hdrsize < sizeof(iph))
144+
return -1;
142145

143146
/* Variable-length IPv4 header, need to use byte-based arithmetic */
144147
if (nh->pos + hdrsize > data_end)
@@ -232,10 +235,15 @@ static __always_inline int parse_tcphdr(struct hdr_cursor *nh,
232235
return -1;
233236

234237
len = h->doff * 4;
235-
if ((void *) h + len > data_end)
238+
/* Sanity check packet field is valid */
239+
if(len < sizeof(h))
236240
return -1;
237241

238-
nh->pos = h + 1;
242+
/* Variable-length TCP header, need to use byte-based arithmetic */
243+
if (nh->pos + len > data_end)
244+
return -1;
245+
246+
nh->pos += len;
239247
*tcphdr = h;
240248

241249
return len;

0 commit comments

Comments
 (0)