Skip to content

Commit

Permalink
examples:dns_matching: fix key length and buffer overrun
Browse files Browse the repository at this point in the history
Changed key length to 255, maximum length of DNS domain name.
Also fixed double increment of loop variable. These both changes
fix buffer overrun.

Signed-off-by: Prashant Bhole <[email protected]>
  • Loading branch information
pbhole committed Sep 28, 2017
1 parent a135d89 commit 07c21f0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions examples/networking/dns_matching/dns_matching.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ struct dns_char_t
} BPF_PACKET_HEADER;

struct Key {
unsigned char p[32];
unsigned char p[255];
};

struct Leaf {
Expand Down Expand Up @@ -85,8 +85,8 @@ int dns_matching(struct __sk_buff *skb)
u16 i = 0;
struct dns_char_t *c;
// This unroll worked not in latest BCC version.
for(u8 j = 0; i<255;i++){
if (cursor == sentinel) goto end; c = cursor_advance(cursor, 1); key.p[i++] = c->c;
for(i = 0; i<255;i++){
if (cursor == sentinel) goto end; c = cursor_advance(cursor, 1); key.p[i] = c->c;
}
end:
{}
Expand Down
4 changes: 2 additions & 2 deletions examples/networking/dns_matching/dns_matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@


def encode_dns(name):
size = 32
if len(name) > 253:
size = 255
if len(name) > 255:
raise Exception("DNS Name too long.")
b = bytearray(size)
i = 0;
Expand Down

0 comments on commit 07c21f0

Please sign in to comment.