From 2e06c8c9278ab283907f3bb9d1fa28c5edb5f1e4 Mon Sep 17 00:00:00 2001 From: Dmitry Kozlov Date: Thu, 21 Dec 2017 15:37:52 +0300 Subject: radius: allocate memory for string attributes --- accel-pppd/radius/packet.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) (limited to 'accel-pppd/radius') diff --git a/accel-pppd/radius/packet.c b/accel-pppd/radius/packet.c index a1fe7549..f507ab2b 100644 --- a/accel-pppd/radius/packet.c +++ b/accel-pppd/radius/packet.c @@ -117,7 +117,7 @@ int rad_packet_recv(int fd, struct rad_packet_t **p, struct sockaddr_in *addr) struct rad_attr_t *attr; struct rad_dict_attr_t *da; struct rad_dict_vendor_t *vendor; - uint8_t *ptr, *endptr; + uint8_t *ptr; int n, id, len, vendor_id; socklen_t addr_len = sizeof(*addr); @@ -134,8 +134,6 @@ int rad_packet_recv(int fd, struct rad_packet_t **p, struct sockaddr_in *addr) goto out_err; } - endptr = ptr + REQ_LENGTH_MAX; - pack->buf = ptr; clock_gettime(CLOCK_MONOTONIC, &pack->tv); @@ -228,12 +226,11 @@ int rad_packet_recv(int fd, struct rad_packet_t **p, struct sockaddr_in *addr) if (!da->array) { switch (da->type) { case ATTR_TYPE_STRING: - if (ptr + len == endptr) { - attr->alloc = 1; - attr->val.string = _malloc(len + 1); - memcpy(attr->val.string, ptr, len); - break; - } + attr->alloc = 1; + attr->val.string = _malloc(len + 1); + memcpy(attr->val.string, ptr, len); + attr->val.string[len] = 0; + break; case ATTR_TYPE_OCTETS: case ATTR_TYPE_ETHER: case ATTR_TYPE_TLV: @@ -269,11 +266,6 @@ int rad_packet_recv(int fd, struct rad_packet_t **p, struct sockaddr_in *addr) n -= 2 + len; } - list_for_each_entry(attr, &pack->attrs, entry) { - if (attr->attr->type == ATTR_TYPE_STRING) - attr->val.string[attr->len] = 0; - } - *p = pack; return 0; -- cgit v1.2.3