Skip to content

Commit

Permalink
Move vp_octets and vp_strvalue to pointer
Browse files Browse the repository at this point in the history
which shrinks the VALUE_PAIR structure, and removes
all length limitations on the attributes.

The code audit still needs to be finished.
  • Loading branch information
alandekok committed May 6, 2013
1 parent 8e8c8c4 commit 71f29ed
Show file tree
Hide file tree
Showing 51 changed files with 481 additions and 448 deletions.
2 changes: 1 addition & 1 deletion src/include/dhcp.h
Expand Up @@ -41,7 +41,7 @@ int fr_dhcp_add_arp_entry(int fd, char const *interface, VALUE_PAIR *hwvp, VALUE

int fr_dhcp_encode(RADIUS_PACKET *packet);
ssize_t fr_dhcp_decode_options(RADIUS_PACKET *packet,
uint8_t *data, size_t len, VALUE_PAIR **head);
uint8_t const *data, size_t len, VALUE_PAIR **head);
int fr_dhcp_decode(RADIUS_PACKET *packet);

/*
Expand Down
4 changes: 2 additions & 2 deletions src/include/libradius.h
Expand Up @@ -150,8 +150,8 @@ typedef struct dict_vendor {
} DICT_VENDOR;

typedef union value_pair_data {
char strvalue[MAX_STRING_LEN];
uint8_t octets[MAX_STRING_LEN];
char const *strvalue;
uint8_t const *octets;
struct in_addr ipaddr;
struct in6_addr ipv6addr;
uint32_t date;
Expand Down
3 changes: 0 additions & 3 deletions src/include/radiusd.h
Expand Up @@ -592,9 +592,6 @@ int radius_exec_program(char const *, REQUEST *, int,
int shell_escape);
void exec_trigger(REQUEST *request, CONF_SECTION *cs, char const *name, int quench);

/* timestr.c */
int timestr_match(char *, time_t);

/* valuepair.c */
int paircompare_register(unsigned int attr, int otherattr,
RAD_COMPARE_FUNC func,
Expand Down
15 changes: 12 additions & 3 deletions src/lib/filters.c
Expand Up @@ -966,6 +966,7 @@ ascend_parse_filter(VALUE_PAIR *pair)
int argc;
char *argv[32];
ascend_filter_t filter;
char *p;

rcode = -1;

Expand All @@ -982,8 +983,12 @@ ascend_parse_filter(VALUE_PAIR *pair)
* Once the filter is *completelty* parsed, then we will
* over-write it with the final binary filter.
*/
argc = str2argv(pair->vp_strvalue, argv, 32);
if (argc < 3) return -1;
p = talloc_strdup(pair, pair->vp_strvalue);
argc = str2argv(p, argv, 32);
if (argc < 3) {
talloc_free(p);
return -1;
}

/*
* Decide which filter type it is: ip, ipx, or generic
Expand All @@ -1003,6 +1008,7 @@ ascend_parse_filter(VALUE_PAIR *pair)

default:
fr_strerror_printf("Unknown Ascend filter type \"%s\"", argv[0]);
talloc_free(p);
return -1;
break;
}
Expand All @@ -1022,6 +1028,7 @@ ascend_parse_filter(VALUE_PAIR *pair)

default:
fr_strerror_printf("Unknown Ascend filter direction \"%s\"", argv[1]);
talloc_free(p);
return -1;
break;
}
Expand All @@ -1041,6 +1048,7 @@ ascend_parse_filter(VALUE_PAIR *pair)

default:
fr_strerror_printf("Unknown Ascend filter action \"%s\"", argv[2]);
talloc_free(p);
return -1;
break;
}
Expand Down Expand Up @@ -1069,6 +1077,7 @@ ascend_parse_filter(VALUE_PAIR *pair)
memcpy(pair->vp_filter, &filter, sizeof(filter));
}

talloc_free(p);
return rcode;

#if 0
Expand Down Expand Up @@ -1098,7 +1107,7 @@ ascend_parse_filter(VALUE_PAIR *pair)
}

if( rc != -1 ) {
memcpy( pair->vp_strvalue, &radFil, pair->length );
pairmemcpy(pair, &radFil, pair->length );
}
return(rc);

Expand Down
11 changes: 7 additions & 4 deletions src/lib/radius.c
Expand Up @@ -3156,6 +3156,7 @@ static ssize_t data2vp(RADIUS_PACKET const *packet,
DICT_VENDOR *dv;
VALUE_PAIR *vp;
const uint8_t *data = start;
char *p;
uint8_t buffer[256];

if (!da || (attrlen > 253) || (attrlen > packetlen) ||
Expand Down Expand Up @@ -3467,13 +3468,15 @@ static ssize_t data2vp(RADIUS_PACKET const *packet,

switch (da->type) {
case PW_TYPE_STRING:
memcpy(vp->vp_strvalue, data, vp->length);
vp->vp_strvalue[vp->length] = '\0';
p = talloc_array(vp, char, vp->length + 1);
memcpy(p, data, vp->length);
p[vp->length] = '\0';
vp->vp_strvalue = p;
break;

case PW_TYPE_OCTETS:
case PW_TYPE_ABINARY:
memcpy(vp->vp_octets, data, vp->length);
vp->vp_octets = talloc_memdup(vp, data, vp->length);
break;

case PW_TYPE_BYTE:
Expand Down Expand Up @@ -3543,7 +3546,7 @@ static ssize_t data2vp(RADIUS_PACKET const *packet,
mask = ~mask;
mask = htonl(mask);
addr &= mask;
memcpy(vp->vp_octets + 2, &addr, sizeof(addr));
memcpy(vp->vp_ipv4prefix + 2, &addr, sizeof(addr));
}
break;

Expand Down

0 comments on commit 71f29ed

Please sign in to comment.