]> git.pld-linux.org Git - packages/tcpdump.git/blob - tcpdump-isakmp-security.patch
- added isakmp-security patch (CAN-2004-0057, CAN-2004-0183, CAN-2004-0184
[packages/tcpdump.git] / tcpdump-isakmp-security.patch
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
4 @@ -60,31 +60,31 @@
5  #endif
6  
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 *,
49 @@ -112,8 +112,8 @@
50  };
51  
52  /* isakmp->np */
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) = {
57         NULL,
58         isakmp_sa_print,
59         isakmp_p_print,
60 @@ -321,15 +321,20 @@
61         return 0;
62  }
63  
64 -static void
65 +static int
66  rawprint(caddr_t loc, size_t len)
67  {
68         static u_char *p;
69         size_t i;
70  
71 +       TCHECK2(*loc, len);
72 +       
73         p = (u_char *)loc;
74         for (i = 0; i < len; i++)
75                 printf("%02x", p[i] & 0xff);
76 +       return 1;
77 +trunc:
78 +       return 0;
79  }
80  
81  struct attrmap {
82 @@ -410,8 +415,9 @@
83  }
84  
85  static const u_char *
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)
91  {
92         const struct isakmp_pl_sa *p;
93         struct isakmp_pl_sa sa;
94 @@ -423,6 +429,7 @@
95         printf("%s:", NPSTR(ISAKMP_NPTYPE_SA));
96  
97         p = (struct isakmp_pl_sa *)ext;
98 +       TCHECK(*p);
99         safememcpy(&sa, ext, sizeof(sa));
100         doi = ntohl(sa.doi);
101         sit = ntohl(sa.sit);
102 @@ -449,22 +456,28 @@
103  
104         np = (u_char *)ext + sizeof(sa);
105         if (sit != 0x01) {
106 +               TCHECK2(*(ext + 1), sizeof(ident));
107                 safememcpy(&ident, ext + 1, sizeof(ident));
108                 printf(" ident=%u", (u_int32_t)ntohl(ident));
109                 np += sizeof(ident);
110         }
111  
112         ext = (struct isakmp_gen *)np;
113 +       TCHECK(*ext);
114  
115         cp = isakmp_sub_print(ISAKMP_NPTYPE_P, ext, ep, phase, doi, proto0,
116                 depth);
117  
118         return cp;
119 +trunc:
120 +       printf(" [|%s]", NPSTR(ISAKMP_NPTYPE_SA));
121 +       return NULL;
122  }
123  
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)
130  {
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));
135  
136         p = (struct isakmp_pl_p *)ext;
137 +       TCHECK(*p);
138         safememcpy(&prop, ext, sizeof(prop));
139         printf(" #%d protoid=%s transform=%d",
140                 prop.p_no, PROTOIDSTR(prop.prot_id), prop.num_t);
141         if (prop.spi_size) {
142                 printf(" spi=");
143 -               rawprint((caddr_t)(p + 1), prop.spi_size);
144 +               if (!rawprint((caddr_t)(p + 1), prop.spi_size))
145 +                       goto trunc;
146         }
147  
148         ext = (struct isakmp_gen *)((u_char *)(p + 1) + prop.spi_size);
149 +       TCHECK(*ext);
150  
151         cp = isakmp_sub_print(ISAKMP_NPTYPE_T, ext, ep, phase, doi0,
152                 prop.prot_id, depth);
153  
154         return cp;
155 +trunc:
156 +       printf(" [|%s]", NPSTR(ISAKMP_NPTYPE_P));
157 +       return NULL;
158  }
159  
160  static const char *isakmp_p_map[] = {
161 @@ -546,9 +565,9 @@
162  };
163  
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,
167 -       int depth _U_)
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_)
171  {
172         const struct isakmp_pl_t *p;
173         struct isakmp_pl_t t;
174 @@ -561,6 +580,7 @@
175         printf("%s:", NPSTR(ISAKMP_NPTYPE_T));
176  
177         p = (struct isakmp_pl_t *)ext;
178 +       TCHECK(*p);
179         safememcpy(&t, ext, sizeof(t));
180  
181         switch (proto) {
182 @@ -596,7 +616,7 @@
183         else
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) {
189                 if (map && nmap) {
190                         cp = isakmp_attrmap_print(cp, (ep < ep2) ? ep : ep2,
191 @@ -607,30 +627,38 @@
192         if (ep < ep2)
193                 printf("...");
194         return cp;
195 +trunc:
196 +       printf(" [|%s]", NPSTR(ISAKMP_NPTYPE_T));
197 +       return NULL;
198  }
199  
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_,
203 -       int depth _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_)
207  {
208         struct isakmp_gen e;
209  
210         printf("%s:", NPSTR(ISAKMP_NPTYPE_KE));
211  
212 +       TCHECK(*ext);
213         safememcpy(&e, ext, sizeof(e));
214         printf(" key len=%d", ntohs(e.len) - 4);
215         if (2 < vflag && 4 < ntohs(e.len)) {
216                 printf(" ");
217 -               rawprint((caddr_t)(ext + 1), ntohs(e.len) - 4);
218 +               if (!rawprint((caddr_t)(ext + 1), ntohs(e.len) - 4))
219 +                       goto trunc;
220         }
221         return (u_char *)ext + ntohs(e.len);
222 +trunc:
223 +       printf(" [|%s]", NPSTR(ISAKMP_NPTYPE_KE));
224 +       return NULL;
225  }
226  
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_,
230 -       int depth _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_)
234  {
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));
239  
240         p = (struct isakmp_pl_id *)ext;
241 +       TCHECK(*p);
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);
246 -       else
247 +               len = item_len - sizeof(*p);
248 +       } else {
249                 data = NULL;
250 -       len = ntohs(id.h.len) - sizeof(*p);
251 +               len = 0;
252 +       }
253  
254  #if 0 /*debug*/
255         printf(" [phase=%d doi=%d proto=%d]", phase, doi, proto);
256 @@ -679,6 +710,7 @@
257                 struct protoent *pe;
258  
259                 p = (struct ipsecdoi_id *)ext;
260 +               TCHECK(*p);
261                 safememcpy(&id, ext, sizeof(id));
262                 printf(" idtype=%s", STR_OR_ID(id.type, ipsecidtypestr));
263                 if (id.proto_id) {
264 @@ -698,9 +730,15 @@
265                 printf(" port=%d", ntohs(id.port));
266                 if (!len)
267                         break;
268 +               if (data == NULL)
269 +                       goto trunc;
270 +               TCHECK2(*data, len);
271                 switch (id.type) {
272                 case IPSECDOI_ID_IPV4_ADDR:
273 -                       printf(" len=%d %s", len, ipaddr_string(data));
274 +                       if (len < 4)
275 +                               printf(" len=%d [bad: < 4]", len);
276 +                       else
277 +                               printf(" len=%d %s", len, ipaddr_string(data));
278                         len = 0;
279                         break;
280                 case IPSECDOI_ID_FQDN:
281 @@ -716,39 +754,60 @@
282                 case IPSECDOI_ID_IPV4_ADDR_SUBNET:
283                     {
284                         const u_char *mask;
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]);
289 +                       if (len < 8)
290 +                               printf(" len=%d [bad: < 8]", len);
291 +                       else {
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]);
296 +                       }
297                         len = 0;
298                         break;
299                     }
300  #ifdef INET6
301                 case IPSECDOI_ID_IPV6_ADDR:
302 -                       printf(" len=%d %s", len, ip6addr_string(data));
303 +                       if (len < 16)
304 +                               printf(" len=%d [bad: < 16]", len);
305 +                       else
306 +                               printf(" len=%d %s", len, ip6addr_string(data));
307                         len = 0;
308                         break;
309                 case IPSECDOI_ID_IPV6_ADDR_SUBNET:
310                     {
311                         const u_int32_t *mask;
312 -                       mask = (u_int32_t *)(data + sizeof(struct in6_addr));
313 -                       /*XXX*/
314 -                       printf(" len=%d %s/0x%08x%08x%08x%08x", len,
315 -                               ip6addr_string(data),
316 -                               mask[0], mask[1], mask[2], mask[3]);
317 +                       if (len < 20)
318 +                               printf(" len=%d [bad: < 20]", len);
319 +                       else {
320 +                               mask = (u_int32_t *)(data + sizeof(struct in6_addr));
321 +                               /*XXX*/
322 +                               printf(" len=%d %s/0x%08x%08x%08x%08x", len,
323 +                                       ip6addr_string(data),
324 +                                       mask[0], mask[1], mask[2], mask[3]);
325 +                       }
326                         len = 0;
327                         break;
328                     }
329  #endif /*INET6*/
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)));
333 +                       if (len < 8)
334 +                               printf(" len=%d [bad: < 8]", len);
335 +                       else {
336 +                               printf(" len=%d %s-%s", len,
337 +                                       ipaddr_string(data),
338 +                                       ipaddr_string(data + sizeof(struct in_addr)));
339 +                       }
340                         len = 0;
341                         break;
342  #ifdef INET6
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)));
346 +                       if (len < 32)
347 +                               printf(" len=%d [bad: < 32]", len);
348 +                       else {
349 +                               printf(" len=%d %s-%s", len,
350 +                                       ip6addr_string(data),
351 +                                       ip6addr_string(data + sizeof(struct in6_addr)));
352 +                       }
353                         len = 0;
354                         break;
355  #endif /*INET6*/
356 @@ -764,16 +823,20 @@
357                 printf(" len=%d", len);
358                 if (2 < vflag) {
359                         printf(" ");
360 -                       rawprint((caddr_t)data, len);
361 +                       if (!rawprint((caddr_t)data, len))
362 +                               goto trunc;
363                 }
364         }
365 -       return (u_char *)ext + ntohs(id.h.len);
366 +       return (u_char *)ext + item_len;
367 +trunc:
368 +       printf(" [|%s]", NPSTR(ISAKMP_NPTYPE_ID));
369 +       return NULL;
370  }
371  
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_,
375 -       int depth _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_)
379  {
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));
384  
385         p = (struct isakmp_pl_cert *)ext;
386 +       TCHECK(*p);
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) {
393                 printf(" ");
394 -               rawprint((caddr_t)(ext + 1), ntohs(cert.h.len) - 4);
395 +               if (!rawprint((caddr_t)(ext + 1), item_len - 4))
396 +                       goto trunc;
397         }
398 -       return (u_char *)ext + ntohs(cert.h.len);
399 +       return (u_char *)ext + item_len;
400 +trunc:
401 +       printf(" [|%s]", NPSTR(ISAKMP_NPTYPE_CERT));
402 +       return NULL;
403  }
404  
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_,
408 -       int depth _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_)
412  {
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));
417  
418         p = (struct isakmp_pl_cert *)ext;
419 +       TCHECK(*p);
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) {
426                 printf(" ");
427 -               rawprint((caddr_t)(ext + 1), ntohs(cert.h.len) - 4);
428 +               if (!rawprint((caddr_t)(ext + 1), item_len - 4))
429 +                       goto trunc;
430         }
431 -       return (u_char *)ext + ntohs(cert.h.len);
432 +       return (u_char *)ext + item_len;
433 +trunc:
434 +       printf(" [|%s]", NPSTR(ISAKMP_NPTYPE_CR));
435 +       return NULL;
436  }
437  
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_,
441 -       int depth _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_)
445  {
446         struct isakmp_gen e;
447  
448         printf("%s:", NPSTR(ISAKMP_NPTYPE_HASH));
449  
450 +       TCHECK(*ext);
451         safememcpy(&e, ext, sizeof(e));
452         printf(" len=%d", ntohs(e.len) - 4);
453         if (2 < vflag && 4 < ntohs(e.len)) {
454                 printf(" ");
455 -               rawprint((caddr_t)(ext + 1), ntohs(e.len) - 4);
456 +               if (!rawprint((caddr_t)(ext + 1), ntohs(e.len) - 4))
457 +                       goto trunc;
458         }
459         return (u_char *)ext + ntohs(e.len);
460 +trunc:
461 +       printf(" [|%s]", NPSTR(ISAKMP_NPTYPE_HASH));
462 +       return NULL;
463  }
464  
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_,
468 -       int depth _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_)
472  {
473         struct isakmp_gen e;
474  
475         printf("%s:", NPSTR(ISAKMP_NPTYPE_SIG));
476  
477 +       TCHECK(*ext);
478         safememcpy(&e, ext, sizeof(e));
479         printf(" len=%d", ntohs(e.len) - 4);
480         if (2 < vflag && 4 < ntohs(e.len)) {
481                 printf(" ");
482 -               rawprint((caddr_t)(ext + 1), ntohs(e.len) - 4);
483 +               if (!rawprint((caddr_t)(ext + 1), ntohs(e.len) - 4))
484 +                       goto trunc;
485         }
486         return (u_char *)ext + ntohs(e.len);
487 +trunc:
488 +       printf(" [|%s]", NPSTR(ISAKMP_NPTYPE_SIG));
489 +       return NULL;
490  }
491  
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_,
495 -       int depth _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_)
499  {
500         struct isakmp_gen e;
501  
502         printf("%s:", NPSTR(ISAKMP_NPTYPE_NONCE));
503  
504 +       TCHECK(*ext);
505         safememcpy(&e, ext, sizeof(e));
506         printf(" n len=%d", ntohs(e.len) - 4);
507         if (2 < vflag && 4 < ntohs(e.len)) {
508                 printf(" ");
509 -               rawprint((caddr_t)(ext + 1), ntohs(e.len) - 4);
510 +               if (!rawprint((caddr_t)(ext + 1), ntohs(e.len) - 4))
511 +                       goto trunc;
512         }
513         return (u_char *)ext + ntohs(e.len);
514 +trunc:
515 +       printf(" [|%s]", NPSTR(ISAKMP_NPTYPE_NONCE));
516 +       return NULL;
517  }
518  
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)
525  {
526         struct isakmp_pl_n *p, n;
527         const u_char *cp;
528 @@ -934,6 +1023,7 @@
529         printf("%s:", NPSTR(ISAKMP_NPTYPE_N));
530  
531         p = (struct isakmp_pl_n *)ext;
532 +       TCHECK(*p);
533         safememcpy(&n, ext, sizeof(n));
534         doi = ntohl(n.doi);
535         proto = n.prot_id;
536 @@ -950,7 +1040,8 @@
537                         printf(" type=%s", numstr(ntohs(n.type)));
538                 if (n.spi_size) {
539                         printf(" spi=");
540 -                       rawprint((caddr_t)(p + 1), n.spi_size);
541 +                       if (!rawprint((caddr_t)(p + 1), n.spi_size))
542 +                               goto trunc;
543                 }
544                 return (u_char *)(p + 1) + n.spi_size;
545         }
546 @@ -969,11 +1060,12 @@
547                 printf(" type=%s", numstr(ntohs(n.type)));
548         if (n.spi_size) {
549                 printf(" spi=");
550 -               rawprint((caddr_t)(p + 1), n.spi_size);
551 +               if (!rawprint((caddr_t)(p + 1), n.spi_size))
552 +                       goto trunc;
553         }
554  
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;
558  
559         if (cp < ep) {
560                 printf(" orig=(");
561 @@ -1000,19 +1092,21 @@
562                         break;
563                 default:
564                         /* NULL is dummy */
565 -                       isakmp_print(cp,
566 -                               ntohs(n.h.len) - sizeof(*p) - n.spi_size,
567 +                       isakmp_print(cp, item_len - sizeof(*p) - n.spi_size,
568                                 NULL);
569                 }
570                 printf(")");
571         }
572 -       return (u_char *)ext + ntohs(n.h.len);
573 +       return (u_char *)ext + item_len;
574 +trunc:
575 +       printf(" [|%s]", NPSTR(ISAKMP_NPTYPE_N));
576 +       return NULL;
577  }
578  
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_,
582 -       int depth _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_)
586  {
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));
591  
592         p = (struct isakmp_pl_d *)ext;
593 +       TCHECK(*p);
594         safememcpy(&d, ext, sizeof(d));
595         doi = ntohl(d.doi);
596         proto = d.prot_id;
597 @@ -1041,28 +1136,37 @@
598         for (i = 0; i < ntohs(d.num_spi); i++) {
599                 if (i != 0)
600                         printf(",");
601 -               rawprint((caddr_t)q, d.spi_size);
602 +               if (!rawprint((caddr_t)q, d.spi_size))
603 +                       goto trunc;
604                 q += d.spi_size;
605         }
606         return q;
607 +trunc:
608 +       printf(" [|%s]", NPSTR(ISAKMP_NPTYPE_D));
609 +       return NULL;
610  }
611  
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_,
615 -       int depth _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_)
619  {
620         struct isakmp_gen e;
621  
622         printf("%s:", NPSTR(ISAKMP_NPTYPE_VID));
623  
624 +       TCHECK(*ext);
625         safememcpy(&e, ext, sizeof(e));
626         printf(" len=%d", ntohs(e.len) - 4);
627         if (2 < vflag && 4 < ntohs(e.len)) {
628                 printf(" ");
629 -               rawprint((caddr_t)(ext + 1), ntohs(e.len) - 4);
630 +               if (!rawprint((caddr_t)(ext + 1), ntohs(e.len) - 4))
631 +                       goto trunc;
632         }
633         return (u_char *)ext + ntohs(e.len);
634 +trunc:
635 +       printf(" [|%s]", NPSTR(ISAKMP_NPTYPE_VID));
636 +       return NULL;
637  }
638  
639  static const u_char *
640 @@ -1074,6 +1178,7 @@
641         u_int item_len;
642  
643         cp = (u_char *)ext;
644 +       TCHECK(*ext);
645         safememcpy(&e, ext, sizeof(e));
646  
647         /*
648 @@ -1091,13 +1196,16 @@
649                  * XXX - what if item_len is too short, or too long,
650                  * for this payload type?
651                  */
652 -               cp = (*NPFUNC(np))(ext, ep, phase, doi, proto, depth);
653 +               cp = (*NPFUNC(np))(ext, item_len, ep, phase, doi, proto, depth);
654         } else {
655                 printf("%s", NPSTR(np));
656                 cp += item_len;
657         }
658  
659         return cp;
660 +trunc:
661 +       printf(" [|isakmp]");
662 +       return NULL;
663  }
664  
665  static const u_char *
666 @@ -1111,13 +1219,12 @@
667         cp = (const u_char *)ext;
668  
669         while (np) {
670 +               TCHECK(*ext);
671 +               
672                 safememcpy(&e, ext, sizeof(e));
673  
674 -               if (ep < (u_char *)ext + ntohs(e.len)) {
675 -                       printf(" [|%s]", NPSTR(np));
676 -                       cp = ep + 1;
677 -                       break;
678 -               }
679 +               TCHECK2(*ext, ntohs(e.len));
680 +
681                 depth++;
682                 printf("\n");
683                 for (i = 0; i < depth; i++)
684 @@ -1136,6 +1243,9 @@
685                 ext = (struct isakmp_gen *)cp;
686         }
687         return cp;
688 +trunc:
689 +       printf(" [|%s]", NPSTR(np));
690 +       return NULL;
691  }
692  
693  static char *
694 @@ -1263,7 +1373,7 @@
695  done:
696         if (vflag) {
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);
701                 }
702         }
This page took 0.091992 seconds and 3 git commands to generate.