]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-radius.c
When discussing the "gateway" keyword, don't say that the host must be
[tcpdump] / print-radius.c
index 25999869c262629e0bc8738bfa5c19283383c93c..24d33f8e9c5032400bd1d1b966890eedd9816646 100644 (file)
 
 #ifndef lint
 static const char rcsid[] =
-    "$Id: print-radius.c,v 1.5 2000-12-18 08:16:58 guy Exp $";
+    "$Id: print-radius.c,v 1.7 2001-06-18 09:16:28 guy Exp $";
 #endif
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
 
+#include <string.h>
+
 #include <sys/param.h>
 
 #include <netinet/in.h>
@@ -115,6 +117,7 @@ struct radius_hdr { u_int8_t  code; /* Radius packet code  */
                     u_int8_t  auth[16]; /* Authenticator   */
                   };
 
+#define MIN_RADIUS_LEN 20
 
 struct radius_attr { u_int8_t type; /* Attribute type   */
                      u_int8_t len;  /* Attribute length */
@@ -730,7 +733,7 @@ static void print_attr_strange(register u_char *data, u_int length, u_short attr
 
 
 static void
-radius_attr_print(register u_char *attr, u_int length)
+radius_attr_print(register const u_char *attr, u_int length)
 {
    register const struct radius_attr *rad_attr = (struct radius_attr *)attr;
    
@@ -743,6 +746,11 @@ radius_attr_print(register u_char *attr, u_int length)
    printf(" Attr[ ");
    while (length > 0)
    {
+     if (rad_attr->len == 0)
+     {
+       printf("(zero-length attribute)");
+       return;
+     }
      if ( rad_attr->len <= length )
      {
         if ( !rad_attr->type || (rad_attr->type > (TAM_SIZE(attr_type)-1))  )
@@ -778,17 +786,30 @@ radius_print(const u_char *dat, u_int length)
 {
    register const struct radius_hdr *rad;
    register int i;
+   int len;
    
-   i = min(length, snapend - dat) - sizeof(*rad);
+   i = min(length, snapend - dat);
 
-   if (i < 0) 
+   if (i < MIN_RADIUS_LEN)
    {
          printf(" [|radius]");
          return;
    }
 
    rad = (struct radius_hdr *)dat;
+   len = ntohs(rad->len);
+
+   if (len < MIN_RADIUS_LEN)
+   {
+         printf(" [|radius]");
+         return;
+   }
+
+   if (len < i)
+         i = len;
+   
+   i -= MIN_RADIUS_LEN;
+
    switch (rad->code) 
    {
      case RADCMD_ACCESS_REQ:
@@ -834,5 +855,5 @@ radius_print(const u_char *dat, u_int length)
    printf(" [id %d]", rad->id);
  
    if (i)
-      radius_attr_print( ((u_char *)(rad+1)), i);  
+      radius_attr_print( dat + MIN_RADIUS_LEN, i);  
 }