From aef76d153fadd34d948816c81ed70f8cf02382ea Mon Sep 17 00:00:00 2001 From: Sam Hartman Date: Mon, 25 Mar 2013 09:49:23 -0400 Subject: [PATCH] chbind: update length calculation --- src/modules/rlm_eap/libeap/eap_chbind.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/modules/rlm_eap/libeap/eap_chbind.c b/src/modules/rlm_eap/libeap/eap_chbind.c index b62115a..c5174ea 100644 --- a/src/modules/rlm_eap/libeap/eap_chbind.c +++ b/src/modules/rlm_eap/libeap/eap_chbind.c @@ -201,7 +201,7 @@ size_t chbind_get_data(CHBIND_PACKET_T *chbind_packet, uint8_t *chbind_build_response(REQUEST *req, size_t *resp_len) { uint8_t *resp; - uint16_t rlen, len = 0; + uint16_t pos, len = 0; VALUE_PAIR *vp = NULL; *resp_len = 0; @@ -223,18 +223,19 @@ uint8_t *chbind_build_response(REQUEST *req, size_t *resp_len) DEBUG("end chbind response\n"); } /* Encode the chbind attributes into the response */ - for (vp = req->reply->vps, rlen = 4; - (vp != NULL) && (rlen < MAX_PACKET_LEN + 4); - rlen += len) { - len = rad_vp2attr(NULL, NULL, NULL, (const VALUE_PAIR **) &vp, &resp[rlen], (MAX_PACKET_LEN + 4) - rlen); + for (vp = req->reply->vps, pos = 4; + (vp != NULL) && (pos < MAX_PACKET_LEN + 4); + pos += len) { + len = rad_vp2attr(NULL, NULL, NULL, (const VALUE_PAIR **) &vp, &resp[pos], (MAX_PACKET_LEN + 4) - pos); } + len = pos-4; /*length covers ns-specific only*/ /* Write the length field into the header */ - resp[1] = (uint8_t)(rlen >> 8); - resp[2] = (uint8_t)(rlen & 0x00FF); + resp[1] = (uint8_t)(len >> 8); + resp[2] = (uint8_t)(len & 0x00FF); /* Output the length of the entire response (attrs + header) */ - *resp_len = rlen + 4; + *resp_len = len + 4; return resp; } -- 2.1.4