1 Backport from tcpdump-3.8.3, fixes CAN-2004-0057, CAN-2004-0183, CAN-2004-0184.
2 --- tcpdump-3.8.1/print-isakmp.c Sat Dec 20 11:02:46 2003
3 +++ tcpdump-3.8.3/print-isakmp.c Wed Mar 24 02:32:42 2004
7 static const u_char *isakmp_sa_print(const struct isakmp_gen *,
8 - const u_char *, u_int32_t, u_int32_t, u_int32_t, int);
9 + u_int, const u_char *, u_int32_t, u_int32_t, u_int32_t, int);
10 static const u_char *isakmp_p_print(const struct isakmp_gen *,
11 - const u_char *, u_int32_t, u_int32_t, u_int32_t, int);
12 + u_int, const u_char *, u_int32_t, u_int32_t, u_int32_t, int);
13 static const u_char *isakmp_t_print(const struct isakmp_gen *,
14 - const u_char *, u_int32_t, u_int32_t, u_int32_t, int);
15 + u_int, const u_char *, u_int32_t, u_int32_t, u_int32_t, int);
16 static const u_char *isakmp_ke_print(const struct isakmp_gen *,
17 - const u_char *, u_int32_t, u_int32_t, u_int32_t, int);
18 + u_int, const u_char *, u_int32_t, u_int32_t, u_int32_t, int);
19 static const u_char *isakmp_id_print(const struct isakmp_gen *,
20 - const u_char *, u_int32_t, u_int32_t, u_int32_t, int);
21 + u_int, const u_char *, u_int32_t, u_int32_t, u_int32_t, int);
22 static const u_char *isakmp_cert_print(const struct isakmp_gen *,
23 - const u_char *, u_int32_t, u_int32_t, u_int32_t, int);
24 + u_int, const u_char *, u_int32_t, u_int32_t, u_int32_t, int);
25 static const u_char *isakmp_cr_print(const struct isakmp_gen *,
26 - const u_char *, u_int32_t, u_int32_t, u_int32_t, int);
27 + u_int, const u_char *, u_int32_t, u_int32_t, u_int32_t, int);
28 static const u_char *isakmp_sig_print(const struct isakmp_gen *,
29 - const u_char *, u_int32_t, u_int32_t, u_int32_t, int);
30 + u_int, const u_char *, u_int32_t, u_int32_t, u_int32_t, int);
31 static const u_char *isakmp_hash_print(const struct isakmp_gen *,
32 - const u_char *, u_int32_t, u_int32_t, u_int32_t, int);
33 + u_int, const u_char *, u_int32_t, u_int32_t, u_int32_t, int);
34 static const u_char *isakmp_nonce_print(const struct isakmp_gen *,
35 - const u_char *, u_int32_t, u_int32_t, u_int32_t, int);
36 + u_int, const u_char *, u_int32_t, u_int32_t, u_int32_t, int);
37 static const u_char *isakmp_n_print(const struct isakmp_gen *,
38 - const u_char *, u_int32_t, u_int32_t, u_int32_t, int);
39 + u_int, const u_char *, u_int32_t, u_int32_t, u_int32_t, int);
40 static const u_char *isakmp_d_print(const struct isakmp_gen *,
41 - const u_char *, u_int32_t, u_int32_t, u_int32_t, int);
42 + u_int, const u_char *, u_int32_t, u_int32_t, u_int32_t, int);
43 static const u_char *isakmp_vid_print(const struct isakmp_gen *,
44 - const u_char *, u_int32_t, u_int32_t, u_int32_t, int);
45 + u_int, const u_char *, u_int32_t, u_int32_t, u_int32_t, int);
46 static const u_char *isakmp_sub0_print(u_char, const struct isakmp_gen *,
47 const u_char *, u_int32_t, u_int32_t, u_int32_t, int);
48 static const u_char *isakmp_sub_print(u_char, const struct isakmp_gen *,
53 -static const u_char *(*npfunc[])(const struct isakmp_gen *, const u_char *,
54 - u_int32_t, u_int32_t, u_int32_t, int) = {
55 +static const u_char *(*npfunc[])(const struct isakmp_gen *, u_int,
56 + const u_char *, u_int32_t, u_int32_t, u_int32_t, int) = {
66 rawprint(caddr_t loc, size_t len)
74 for (i = 0; i < len; i++)
75 printf("%02x", p[i] & 0xff);
86 -isakmp_sa_print(const struct isakmp_gen *ext, const u_char *ep, u_int32_t phase,
87 - u_int32_t doi0 _U_, u_int32_t proto0, int depth)
88 +isakmp_sa_print(const struct isakmp_gen *ext, u_int item_len,
89 + const u_char *ep, u_int32_t phase, u_int32_t doi0 _U_,
90 + u_int32_t proto0, int depth)
92 const struct isakmp_pl_sa *p;
93 struct isakmp_pl_sa sa;
95 printf("%s:", NPSTR(ISAKMP_NPTYPE_SA));
97 p = (struct isakmp_pl_sa *)ext;
99 safememcpy(&sa, ext, sizeof(sa));
102 @@ -449,22 +456,28 @@
104 np = (u_char *)ext + sizeof(sa);
106 + TCHECK2(*(ext + 1), sizeof(ident));
107 safememcpy(&ident, ext + 1, sizeof(ident));
108 printf(" ident=%u", (u_int32_t)ntohl(ident));
112 ext = (struct isakmp_gen *)np;
115 cp = isakmp_sub_print(ISAKMP_NPTYPE_P, ext, ep, phase, doi, proto0,
120 + printf(" [|%s]", NPSTR(ISAKMP_NPTYPE_SA));
124 static const u_char *
125 -isakmp_p_print(const struct isakmp_gen *ext, const u_char *ep, u_int32_t phase,
126 - u_int32_t doi0, u_int32_t proto0 _U_, int depth)
127 +isakmp_p_print(const struct isakmp_gen *ext, u_int item_len,
128 + const u_char *ep, u_int32_t phase, u_int32_t doi0,
129 + u_int32_t proto0 _U_, int depth)
131 const struct isakmp_pl_p *p;
132 struct isakmp_pl_p prop;
133 @@ -473,20 +486,26 @@
134 printf("%s:", NPSTR(ISAKMP_NPTYPE_P));
136 p = (struct isakmp_pl_p *)ext;
138 safememcpy(&prop, ext, sizeof(prop));
139 printf(" #%d protoid=%s transform=%d",
140 prop.p_no, PROTOIDSTR(prop.prot_id), prop.num_t);
143 - rawprint((caddr_t)(p + 1), prop.spi_size);
144 + if (!rawprint((caddr_t)(p + 1), prop.spi_size))
148 ext = (struct isakmp_gen *)((u_char *)(p + 1) + prop.spi_size);
151 cp = isakmp_sub_print(ISAKMP_NPTYPE_T, ext, ep, phase, doi0,
152 prop.prot_id, depth);
156 + printf(" [|%s]", NPSTR(ISAKMP_NPTYPE_P));
160 static const char *isakmp_p_map[] = {
164 static const u_char *
165 -isakmp_t_print(const struct isakmp_gen *ext, const u_char *ep,
166 - u_int32_t phase _U_, u_int32_t doi _U_, u_int32_t proto,
168 +isakmp_t_print(const struct isakmp_gen *ext, u_int item_len,
169 + const u_char *ep, u_int32_t phase _U_, u_int32_t doi _U_,
170 + u_int32_t proto, int depth _U_)
172 const struct isakmp_pl_t *p;
173 struct isakmp_pl_t t;
175 printf("%s:", NPSTR(ISAKMP_NPTYPE_T));
177 p = (struct isakmp_pl_t *)ext;
179 safememcpy(&t, ext, sizeof(t));
184 printf(" #%d id=%d ", t.t_no, t.t_id);
185 cp = (u_char *)(p + 1);
186 - ep2 = (u_char *)p + ntohs(t.h.len);
187 + ep2 = (u_char *)p + item_len;
188 while (cp < ep && cp < ep2) {
190 cp = isakmp_attrmap_print(cp, (ep < ep2) ? ep : ep2,
191 @@ -607,30 +627,38 @@
196 + printf(" [|%s]", NPSTR(ISAKMP_NPTYPE_T));
200 static const u_char *
201 -isakmp_ke_print(const struct isakmp_gen *ext, const u_char *ep _U_,
202 - u_int32_t phase _U_, u_int32_t doi _U_, u_int32_t proto _U_,
204 +isakmp_ke_print(const struct isakmp_gen *ext, u_int item_len,
205 + const u_char *ep, u_int32_t phase _U_, u_int32_t doi _U_,
206 + u_int32_t proto _U_, int depth _U_)
210 printf("%s:", NPSTR(ISAKMP_NPTYPE_KE));
213 safememcpy(&e, ext, sizeof(e));
214 printf(" key len=%d", ntohs(e.len) - 4);
215 if (2 < vflag && 4 < ntohs(e.len)) {
217 - rawprint((caddr_t)(ext + 1), ntohs(e.len) - 4);
218 + if (!rawprint((caddr_t)(ext + 1), ntohs(e.len) - 4))
221 return (u_char *)ext + ntohs(e.len);
223 + printf(" [|%s]", NPSTR(ISAKMP_NPTYPE_KE));
227 static const u_char *
228 -isakmp_id_print(const struct isakmp_gen *ext, const u_char *ep _U_,
229 - u_int32_t phase, u_int32_t doi _U_, u_int32_t proto _U_,
231 +isakmp_id_print(const struct isakmp_gen *ext, u_int item_len,
232 + const u_char *ep, u_int32_t phase, u_int32_t doi _U_,
233 + u_int32_t proto _U_, int depth _U_)
235 #define USE_IPSECDOI_IN_PHASE1 1
236 const struct isakmp_pl_id *p;
237 @@ -649,12 +677,15 @@
238 printf("%s:", NPSTR(ISAKMP_NPTYPE_ID));
240 p = (struct isakmp_pl_id *)ext;
242 safememcpy(&id, ext, sizeof(id));
243 - if (sizeof(*p) < id.h.len)
244 + if (sizeof(*p) < item_len) {
245 data = (u_char *)(p + 1);
247 + len = item_len - sizeof(*p);
250 - len = ntohs(id.h.len) - sizeof(*p);
255 printf(" [phase=%d doi=%d proto=%d]", phase, doi, proto);
259 p = (struct ipsecdoi_id *)ext;
261 safememcpy(&id, ext, sizeof(id));
262 printf(" idtype=%s", STR_OR_ID(id.type, ipsecidtypestr));
265 printf(" port=%d", ntohs(id.port));
270 + TCHECK2(*data, len);
272 case IPSECDOI_ID_IPV4_ADDR:
273 - printf(" len=%d %s", len, ipaddr_string(data));
275 + printf(" len=%d [bad: < 4]", len);
277 + printf(" len=%d %s", len, ipaddr_string(data));
280 case IPSECDOI_ID_FQDN:
281 @@ -716,39 +754,60 @@
282 case IPSECDOI_ID_IPV4_ADDR_SUBNET:
285 - mask = data + sizeof(struct in_addr);
286 - printf(" len=%d %s/%u.%u.%u.%u", len,
287 - ipaddr_string(data),
288 - mask[0], mask[1], mask[2], mask[3]);
290 + printf(" len=%d [bad: < 8]", len);
292 + mask = data + sizeof(struct in_addr);
293 + printf(" len=%d %s/%u.%u.%u.%u", len,
294 + ipaddr_string(data),
295 + mask[0], mask[1], mask[2], mask[3]);
301 case IPSECDOI_ID_IPV6_ADDR:
302 - printf(" len=%d %s", len, ip6addr_string(data));
304 + printf(" len=%d [bad: < 16]", len);
306 + printf(" len=%d %s", len, ip6addr_string(data));
309 case IPSECDOI_ID_IPV6_ADDR_SUBNET:
311 const u_int32_t *mask;
312 - mask = (u_int32_t *)(data + sizeof(struct in6_addr));
314 - printf(" len=%d %s/0x%08x%08x%08x%08x", len,
315 - ip6addr_string(data),
316 - mask[0], mask[1], mask[2], mask[3]);
318 + printf(" len=%d [bad: < 20]", len);
320 + mask = (u_int32_t *)(data + sizeof(struct in6_addr));
322 + printf(" len=%d %s/0x%08x%08x%08x%08x", len,
323 + ip6addr_string(data),
324 + mask[0], mask[1], mask[2], mask[3]);
330 case IPSECDOI_ID_IPV4_ADDR_RANGE:
331 - printf(" len=%d %s-%s", len, ipaddr_string(data),
332 - ipaddr_string(data + sizeof(struct in_addr)));
334 + printf(" len=%d [bad: < 8]", len);
336 + printf(" len=%d %s-%s", len,
337 + ipaddr_string(data),
338 + ipaddr_string(data + sizeof(struct in_addr)));
343 case IPSECDOI_ID_IPV6_ADDR_RANGE:
344 - printf(" len=%d %s-%s", len, ip6addr_string(data),
345 - ip6addr_string(data + sizeof(struct in6_addr)));
347 + printf(" len=%d [bad: < 32]", len);
349 + printf(" len=%d %s-%s", len,
350 + ip6addr_string(data),
351 + ip6addr_string(data + sizeof(struct in6_addr)));
356 @@ -764,16 +823,20 @@
357 printf(" len=%d", len);
360 - rawprint((caddr_t)data, len);
361 + if (!rawprint((caddr_t)data, len))
365 - return (u_char *)ext + ntohs(id.h.len);
366 + return (u_char *)ext + item_len;
368 + printf(" [|%s]", NPSTR(ISAKMP_NPTYPE_ID));
372 static const u_char *
373 -isakmp_cert_print(const struct isakmp_gen *ext, const u_char *ep _U_,
374 - u_int32_t phase _U_, u_int32_t doi0 _U_, u_int32_t proto0 _U_,
376 +isakmp_cert_print(const struct isakmp_gen *ext, u_int item_len,
377 + const u_char *ep, u_int32_t phase _U_, u_int32_t doi0 _U_,
378 + u_int32_t proto0 _U_, int depth _U_)
380 const struct isakmp_pl_cert *p;
381 struct isakmp_pl_cert cert;
382 @@ -786,20 +849,25 @@
383 printf("%s:", NPSTR(ISAKMP_NPTYPE_CERT));
385 p = (struct isakmp_pl_cert *)ext;
387 safememcpy(&cert, ext, sizeof(cert));
388 - printf(" len=%d", ntohs(cert.h.len) - 4);
389 + printf(" len=%d", item_len - 4);
390 printf(" type=%s", STR_OR_ID((cert.encode), certstr));
391 - if (2 < vflag && 4 < ntohs(cert.h.len)) {
392 + if (2 < vflag && 4 < item_len) {
394 - rawprint((caddr_t)(ext + 1), ntohs(cert.h.len) - 4);
395 + if (!rawprint((caddr_t)(ext + 1), item_len - 4))
398 - return (u_char *)ext + ntohs(cert.h.len);
399 + return (u_char *)ext + item_len;
401 + printf(" [|%s]", NPSTR(ISAKMP_NPTYPE_CERT));
405 static const u_char *
406 -isakmp_cr_print(const struct isakmp_gen *ext, const u_char *ep _U_,
407 - u_int32_t phase _U_, u_int32_t doi0 _U_, u_int32_t proto0 _U_,
409 +isakmp_cr_print(const struct isakmp_gen *ext, u_int item_len,
410 + const u_char *ep, u_int32_t phase _U_, u_int32_t doi0 _U_,
411 + u_int32_t proto0 _U_, int depth _U_)
413 const struct isakmp_pl_cert *p;
414 struct isakmp_pl_cert cert;
415 @@ -812,73 +880,94 @@
416 printf("%s:", NPSTR(ISAKMP_NPTYPE_CR));
418 p = (struct isakmp_pl_cert *)ext;
420 safememcpy(&cert, ext, sizeof(cert));
421 - printf(" len=%d", ntohs(cert.h.len) - 4);
422 + printf(" len=%d", item_len - 4);
423 printf(" type=%s", STR_OR_ID((cert.encode), certstr));
424 - if (2 < vflag && 4 < ntohs(cert.h.len)) {
425 + if (2 < vflag && 4 < item_len) {
427 - rawprint((caddr_t)(ext + 1), ntohs(cert.h.len) - 4);
428 + if (!rawprint((caddr_t)(ext + 1), item_len - 4))
431 - return (u_char *)ext + ntohs(cert.h.len);
432 + return (u_char *)ext + item_len;
434 + printf(" [|%s]", NPSTR(ISAKMP_NPTYPE_CR));
438 static const u_char *
439 -isakmp_hash_print(const struct isakmp_gen *ext, const u_char *ep _U_,
440 - u_int32_t phase _U_, u_int32_t doi _U_, u_int32_t proto _U_,
442 +isakmp_hash_print(const struct isakmp_gen *ext, u_int item_len,
443 + const u_char *ep, u_int32_t phase _U_, u_int32_t doi _U_,
444 + u_int32_t proto _U_, int depth _U_)
448 printf("%s:", NPSTR(ISAKMP_NPTYPE_HASH));
451 safememcpy(&e, ext, sizeof(e));
452 printf(" len=%d", ntohs(e.len) - 4);
453 if (2 < vflag && 4 < ntohs(e.len)) {
455 - rawprint((caddr_t)(ext + 1), ntohs(e.len) - 4);
456 + if (!rawprint((caddr_t)(ext + 1), ntohs(e.len) - 4))
459 return (u_char *)ext + ntohs(e.len);
461 + printf(" [|%s]", NPSTR(ISAKMP_NPTYPE_HASH));
465 static const u_char *
466 -isakmp_sig_print(const struct isakmp_gen *ext, const u_char *ep _U_,
467 - u_int32_t phase _U_, u_int32_t doi _U_, u_int32_t proto _U_,
469 +isakmp_sig_print(const struct isakmp_gen *ext, u_int item_len,
470 + const u_char *ep, u_int32_t phase _U_, u_int32_t doi _U_,
471 + u_int32_t proto _U_, int depth _U_)
475 printf("%s:", NPSTR(ISAKMP_NPTYPE_SIG));
478 safememcpy(&e, ext, sizeof(e));
479 printf(" len=%d", ntohs(e.len) - 4);
480 if (2 < vflag && 4 < ntohs(e.len)) {
482 - rawprint((caddr_t)(ext + 1), ntohs(e.len) - 4);
483 + if (!rawprint((caddr_t)(ext + 1), ntohs(e.len) - 4))
486 return (u_char *)ext + ntohs(e.len);
488 + printf(" [|%s]", NPSTR(ISAKMP_NPTYPE_SIG));
492 static const u_char *
493 -isakmp_nonce_print(const struct isakmp_gen *ext, const u_char *ep _U_,
494 - u_int32_t phase _U_, u_int32_t doi _U_, u_int32_t proto _U_,
496 +isakmp_nonce_print(const struct isakmp_gen *ext, u_int item_len,
497 + const u_char *ep, u_int32_t phase _U_, u_int32_t doi _U_,
498 + u_int32_t proto _U_, int depth _U_)
502 printf("%s:", NPSTR(ISAKMP_NPTYPE_NONCE));
505 safememcpy(&e, ext, sizeof(e));
506 printf(" n len=%d", ntohs(e.len) - 4);
507 if (2 < vflag && 4 < ntohs(e.len)) {
509 - rawprint((caddr_t)(ext + 1), ntohs(e.len) - 4);
510 + if (!rawprint((caddr_t)(ext + 1), ntohs(e.len) - 4))
513 return (u_char *)ext + ntohs(e.len);
515 + printf(" [|%s]", NPSTR(ISAKMP_NPTYPE_NONCE));
519 static const u_char *
520 -isakmp_n_print(const struct isakmp_gen *ext, const u_char *ep, u_int32_t phase,
521 - u_int32_t doi0 _U_, u_int32_t proto0 _U_, int depth)
522 +isakmp_n_print(const struct isakmp_gen *ext, u_int item_len,
523 + const u_char *ep, u_int32_t phase, u_int32_t doi0 _U_,
524 + u_int32_t proto0 _U_, int depth)
526 struct isakmp_pl_n *p, n;
529 printf("%s:", NPSTR(ISAKMP_NPTYPE_N));
531 p = (struct isakmp_pl_n *)ext;
533 safememcpy(&n, ext, sizeof(n));
537 printf(" type=%s", numstr(ntohs(n.type)));
540 - rawprint((caddr_t)(p + 1), n.spi_size);
541 + if (!rawprint((caddr_t)(p + 1), n.spi_size))
544 return (u_char *)(p + 1) + n.spi_size;
546 @@ -969,11 +1060,12 @@
547 printf(" type=%s", numstr(ntohs(n.type)));
550 - rawprint((caddr_t)(p + 1), n.spi_size);
551 + if (!rawprint((caddr_t)(p + 1), n.spi_size))
555 cp = (u_char *)(p + 1) + n.spi_size;
556 - ep2 = (u_char *)p + ntohs(n.h.len);
557 + ep2 = (u_char *)p + item_len;
561 @@ -1000,19 +1092,21 @@
566 - ntohs(n.h.len) - sizeof(*p) - n.spi_size,
567 + isakmp_print(cp, item_len - sizeof(*p) - n.spi_size,
572 - return (u_char *)ext + ntohs(n.h.len);
573 + return (u_char *)ext + item_len;
575 + printf(" [|%s]", NPSTR(ISAKMP_NPTYPE_N));
579 static const u_char *
580 -isakmp_d_print(const struct isakmp_gen *ext, const u_char *ep _U_,
581 - u_int32_t phase _U_, u_int32_t doi0 _U_, u_int32_t proto0 _U_,
583 +isakmp_d_print(const struct isakmp_gen *ext, u_int item_len,
584 + const u_char *ep, u_int32_t phase _U_, u_int32_t doi0 _U_,
585 + u_int32_t proto0 _U_, int depth _U_)
587 const struct isakmp_pl_d *p;
588 struct isakmp_pl_d d;
589 @@ -1024,6 +1118,7 @@
590 printf("%s:", NPSTR(ISAKMP_NPTYPE_D));
592 p = (struct isakmp_pl_d *)ext;
594 safememcpy(&d, ext, sizeof(d));
597 @@ -1041,28 +1136,37 @@
598 for (i = 0; i < ntohs(d.num_spi); i++) {
601 - rawprint((caddr_t)q, d.spi_size);
602 + if (!rawprint((caddr_t)q, d.spi_size))
608 + printf(" [|%s]", NPSTR(ISAKMP_NPTYPE_D));
612 static const u_char *
613 -isakmp_vid_print(const struct isakmp_gen *ext, const u_char *ep _U_,
614 - u_int32_t phase _U_, u_int32_t doi _U_, u_int32_t proto _U_,
616 +isakmp_vid_print(const struct isakmp_gen *ext, u_int item_len,
617 + const u_char *ep, u_int32_t phase _U_, u_int32_t doi _U_,
618 + u_int32_t proto _U_, int depth _U_)
622 printf("%s:", NPSTR(ISAKMP_NPTYPE_VID));
625 safememcpy(&e, ext, sizeof(e));
626 printf(" len=%d", ntohs(e.len) - 4);
627 if (2 < vflag && 4 < ntohs(e.len)) {
629 - rawprint((caddr_t)(ext + 1), ntohs(e.len) - 4);
630 + if (!rawprint((caddr_t)(ext + 1), ntohs(e.len) - 4))
633 return (u_char *)ext + ntohs(e.len);
635 + printf(" [|%s]", NPSTR(ISAKMP_NPTYPE_VID));
639 static const u_char *
640 @@ -1074,6 +1178,7 @@
645 safememcpy(&e, ext, sizeof(e));
648 @@ -1091,13 +1196,16 @@
649 * XXX - what if item_len is too short, or too long,
650 * for this payload type?
652 - cp = (*NPFUNC(np))(ext, ep, phase, doi, proto, depth);
653 + cp = (*NPFUNC(np))(ext, item_len, ep, phase, doi, proto, depth);
655 printf("%s", NPSTR(np));
661 + printf(" [|isakmp]");
665 static const u_char *
666 @@ -1111,13 +1219,12 @@
667 cp = (const u_char *)ext;
672 safememcpy(&e, ext, sizeof(e));
674 - if (ep < (u_char *)ext + ntohs(e.len)) {
675 - printf(" [|%s]", NPSTR(np));
679 + TCHECK2(*ext, ntohs(e.len));
683 for (i = 0; i < depth; i++)
684 @@ -1136,6 +1243,9 @@
685 ext = (struct isakmp_gen *)cp;
689 + printf(" [|%s]", NPSTR(np));
694 @@ -1263,7 +1373,7 @@
697 if (ntohl(base.len) != length) {
698 - printf(" (len mismatch: isakmp %u/ip %d)",
699 + printf(" (len mismatch: isakmp %u/ip %u)",
700 (u_int32_t)ntohl(base.len), length);