#ifndef lint
static const char rcsid[] =
- "$Id: print-radius.c,v 1.6 2001-03-19 03:58:11 guy Exp $";
+ "$Id: print-radius.c,v 1.9 2001-07-15 19:27:45 guy Exp $";
#endif
#ifdef HAVE_CONFIG_H
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 */
}
else
{
- data++;
data_value = EXTRACT_32BITS(data);
}
if ( data_value <= (attr_type[attr_code].siz_subtypes - 1 +
TCHECK2(data[0],4);
attr_time = EXTRACT_32BITS(data);
- strcpy(string, ctime(&attr_time));
+ strlcpy(string, ctime(&attr_time), sizeof(string));
/* Get rid of the newline */
string[24] = '\0';
printf("{%.24s}", string);
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;
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)) )
{
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:
printf(" [id %d]", rad->id);
if (i)
- radius_attr_print( ((u_char *)(rad+1)), i);
+ radius_attr_print( dat + MIN_RADIUS_LEN, i);
}