From fb63e5d509681449e4b2428bc8c023d01895dd9d Mon Sep 17 00:00:00 2001 From: Guillaume Nault Date: Thu, 16 Jan 2014 21:25:23 +0100 Subject: radius: allow creation of zero length attributes Some attributes, like IWF-Session (RFC 4679), may have no payload. Allow the len parameter of rad_packet_add_octets() to be 0 in order to add such attributes (and do the same for rad_packet_change_octets() for API consistency). Signed-off-by: Guillaume Nault --- accel-pppd/radius/packet.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'accel-pppd/radius/packet.c') diff --git a/accel-pppd/radius/packet.c b/accel-pppd/radius/packet.c index 51220672..ace9f6e2 100644 --- a/accel-pppd/radius/packet.c +++ b/accel-pppd/radius/packet.c @@ -450,13 +450,17 @@ int __export rad_packet_add_octets(struct rad_packet_t *pack, const char *vendor ra->vendor = vendor; ra->attr = attr; ra->len = len; - ra->val.octets = _malloc(len); - if (!ra->val.octets) { - log_emerg("radius: out of memory\n"); - _free(ra); - return -1; + + if (len) { + ra->val.octets = _malloc(len); + if (!ra->val.octets) { + log_emerg("radius: out of memory\n"); + _free(ra); + return -1; + } + memcpy(ra->val.octets, val, len); } - memcpy(ra->val.octets, val, len); + list_add_tail(&ra->entry, &pack->attrs); pack->len += (vendor_name ? 8 : 2) + len; @@ -476,7 +480,7 @@ int __export rad_packet_change_octets(struct rad_packet_t *pack, const char *ven return -1; ra->val.octets = _realloc(ra->val.octets, len); - if (!ra->val.octets) { + if (len && !ra->val.octets) { log_emerg("radius: out of memory\n"); return -1; } @@ -485,7 +489,8 @@ int __export rad_packet_change_octets(struct rad_packet_t *pack, const char *ven ra->len = len; } - memcpy(ra->val.octets, val, len); + if (len) + memcpy(ra->val.octets, val, len); return 0; } -- cgit v1.2.3