3
From 4038f83ebf654804829b258dde5e0a508c1c2003 Mon Sep 17 00:00:00 2001
4
From: Guy Harris <guy@alum.mit.edu>
5
Date: Tue, 11 Nov 2014 16:49:39 -0800
6
Subject: [PATCH] Do more bounds checking and length checking.
8
Don't run past the end of the captured data, and don't run past the end
9
of the packet (i.e., don't make the length variable go negative).
11
Also, stop dissecting if the message length isn't valid.
13
print-olsr.c | 56 +++++++++++++++++++++++++++++++++++++++++++-------------
14
1 file changed, 43 insertions(+), 13 deletions(-)
16
Index: tcpdump-4.0.0/print-olsr.c
17
===================================================================
18
--- tcpdump-4.0.0.orig/print-olsr.c 2014-12-03 17:06:47.275721894 -0500
19
+++ tcpdump-4.0.0/print-olsr.c 2014-12-03 17:16:48.016960427 -0500
22
* print a neighbor list with LQ extensions.
26
olsr_print_lq_neighbor (const u_char *msg_data, u_int hello_len)
28
struct olsr_lq_neighbor *lq_neighbor;
30
while (hello_len >= sizeof(struct olsr_lq_neighbor)) {
32
lq_neighbor = (struct olsr_lq_neighbor *)msg_data;
33
+ if (!TTEST(*lq_neighbor))
36
printf("\n\t neighbor %s, link-quality %.2lf%%"
37
", neighbor-link-quality %.2lf%%",
39
msg_data += sizeof(struct olsr_lq_neighbor);
40
hello_len -= sizeof(struct olsr_lq_neighbor);
46
* print a neighbor list.
50
olsr_print_neighbor (const u_char *msg_data, u_int hello_len)
55
while (hello_len >= sizeof(struct in_addr)) {
57
+ if (!TTEST2(*msg_data, sizeof(struct in_addr)))
59
/* print 4 neighbors per line */
61
printf("%s%s", ipaddr_string(msg_data),
63
msg_data += sizeof(struct in_addr);
64
hello_len -= sizeof(struct in_addr);
73
while (tptr < (pptr+length)) {
74
+ int msg_len_valid = 0;
76
if (!TTEST2(*tptr, sizeof(struct olsr_msg)))
80
msg_type = ptr.msg->msg_type;
81
msg_len = EXTRACT_16BITS(ptr.msg->msg_len);
82
+ if ((msg_len >= sizeof (struct olsr_msg))
83
+ && (msg_len <= length))
86
/* infinite loop check */
87
if (msg_type == 0 || msg_len == 0) {
89
ME_TO_DOUBLE(ptr.msg->vtime),
90
EXTRACT_16BITS(ptr.msg->msg_seq),
92
+ if (!msg_len_valid) {
96
msg_tlen = msg_len - sizeof(struct olsr_msg);
97
msg_data = tptr + sizeof(struct olsr_msg);
101
case OLSR_HELLO_LQ_MSG:
102
+ if (msg_tlen < sizeof(struct olsr_hello))
104
if (!TTEST2(*msg_data, sizeof(struct olsr_hello)))
107
@@ -307,10 +322,14 @@
108
msg_tlen -= sizeof(struct olsr_hello_link);
109
hello_len -= sizeof(struct olsr_hello_link);
111
+ if (!TTEST2(*msg_data, hello_len))
113
if (msg_type == OLSR_HELLO_MSG) {
114
- olsr_print_neighbor(msg_data, hello_len);
115
+ if (olsr_print_neighbor(msg_data, hello_len) == -1)
118
- olsr_print_lq_neighbor(msg_data, hello_len);
119
+ if (olsr_print_lq_neighbor(msg_data, hello_len) == -1)
123
msg_data += hello_len;
128
+ if (msg_tlen < sizeof(struct olsr_tc))
130
if (!TTEST2(*msg_data, sizeof(struct olsr_tc)))
134
msg_tlen -= sizeof(struct olsr_tc);
136
if (msg_type == OLSR_TC_MSG) {
137
- olsr_print_neighbor(msg_data, msg_tlen);
138
+ if (olsr_print_neighbor(msg_data, msg_tlen) == -1)
141
- olsr_print_lq_neighbor(msg_data, msg_tlen);
142
+ if (olsr_print_lq_neighbor(msg_data, msg_tlen) == -1)