Skip to content

Commit b340e34

Browse files
committed
Add bounds checking.
1 parent 33ede7f commit b340e34

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

print-aodv.c

+19-9
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
#ifndef lint
3434
static const char rcsid[] _U_ =
35-
"@(#) $Header: /tcpdump/master/tcpdump/print-aodv.c,v 1.10 2003-11-16 09:36:12 guy Exp $ (LBL)";
35+
"@(#) $Header: /tcpdump/master/tcpdump/print-aodv.c,v 1.11 2004-03-24 00:30:19 guy Exp $ (LBL)";
3636
#endif
3737

3838
#ifdef HAVE_CONFIG_H
@@ -143,20 +143,30 @@ aodv_rrep(const union aodv *ap, const u_char *dat, u_int length)
143143
}
144144

145145
static void
146-
aodv_rerr(const union aodv *ap, u_int length)
146+
aodv_rerr(const union aodv *ap, const u_char *dat, u_int length)
147147
{
148+
u_int i;
148149
const struct rerr_unreach *dp = NULL;
149-
int i, j, n, trunc;
150+
int n, trunc;
150151

151-
i = length - offsetof(struct aodv_rerr, r);
152-
j = sizeof(ap->rerr.r.dest[0]);
152+
if (snapend < dat) {
153+
printf(" [|aodv]");
154+
return;
155+
}
156+
i = min(length, (u_int)(snapend - dat));
157+
if (i < offsetof(struct aodv_rerr, r)) {
158+
printf(" [|rerr]");
159+
return;
160+
}
161+
i -= offsetof(struct aodv_rerr, r);
153162
dp = &ap->rerr.r.dest[0];
154-
n = ap->rerr.rerr_dc * j;
163+
n = ap->rerr.rerr_dc * sizeof(ap->rerr.r.dest[0]);
155164
printf(" rerr %s [items %u] [%u]:",
156165
ap->rerr.rerr_flags & RERR_NODELETE ? "[D]" : "",
157166
ap->rerr.rerr_dc, length);
158-
trunc = n - (i/j);
159-
for (; i -= j >= 0; ++dp) {
167+
trunc = n - (i/sizeof(ap->rerr.r.dest[0]));
168+
for (; i >= sizeof(ap->rerr.r.dest[0]);
169+
++dp, i -= sizeof(ap->rerr.r.dest[0])) {
160170
printf(" {%s}(%ld)", ipaddr_string(&dp->u_da),
161171
(unsigned long)EXTRACT_32BITS(&dp->u_ds));
162172
}
@@ -416,7 +426,7 @@ aodv_print(const u_char *dat, u_int length, int is_ip6)
416426
if (is_ip6)
417427
aodv_v6_rerr(ap, length);
418428
else
419-
aodv_rerr(ap, length);
429+
aodv_rerr(ap, dat, length);
420430
break;
421431

422432
case AODV_RREP_ACK:

0 commit comments

Comments
 (0)