]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
various bug fixes for chbind.c
authorAlan T. DeKok <aland@freeradius.org>
Tue, 17 Feb 2026 16:07:46 +0000 (11:07 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 17 Feb 2026 18:31:26 +0000 (13:31 -0500)
src/lib/eap/chbind.c

index e3a84135339da9c63876ff62ff594d2aaabca19b..fb2881fd45834f51bea41c3655c3c0f028c539ff 100644 (file)
@@ -37,7 +37,7 @@ static bool chbind_build_response(request_t *request, CHBIND_REQ *chbind)
 {
        ssize_t                 slen;
        size_t                  total;
-       uint8_t                 *ptr, *end;
+       uint8_t                 *ptr, *start, *end;
        fr_pair_t               const *vp;
        fr_dcursor_t            cursor;
 
@@ -58,9 +58,9 @@ static bool chbind_build_response(request_t *request, CHBIND_REQ *chbind)
         *      No attributes: just send a 1-byte response code.
         */
        if (!total) {
-               ptr = talloc_zero_array(chbind, uint8_t, 1);
+               ptr = start = talloc_zero_array(chbind, uint8_t, 1);
        } else {
-               ptr = talloc_zero_array(chbind, uint8_t, total + 4);
+               ptr = start = talloc_zero_array(chbind, uint8_t, total + 4);
        }
        if (!ptr) return false;
        chbind->response = (chbind_packet_t *) ptr;
@@ -94,22 +94,24 @@ static bool chbind_build_response(request_t *request, CHBIND_REQ *chbind)
        while ((vp = fr_dcursor_current(&cursor)) && (ptr < end)) {
                /*
                 *      Skip things which shouldn't be in channel bindings.
-                *      i.e. tagged, encrypted, or extended attributes
                 */
-               if (vp->da->flags.subtype) {
+               if (vp->da->flags.internal || (!vp->da->flags.extra && vp->da->flags.subtype) ||
+                   (vp->da == attr_message_authenticator)) {
                next:
                        fr_dcursor_next(&cursor);
                        continue;
                }
+
                if (vp->da == attr_message_authenticator) goto next;
 
                slen = fr_radius_encode_pair(&FR_DBUFF_TMP(ptr, end), &cursor, NULL);
                if (slen < 0) {
                        RPERROR("Failed encoding chbind response");
-
-                       talloc_free(ptr);
+                       chbind->response = NULL;
+                       talloc_free(start);
                        return false;
                }
+
                ptr += slen;
        }
 
@@ -191,7 +193,7 @@ fr_radius_packet_code_t chbind_process(request_t *request, CHBIND_REQ *chbind)
 
        /* Add the username to the fake request */
        if (chbind->username) {
-               vp = fr_pair_copy(fake->request_ctx, chbind->username);
+               MEM(vp = fr_pair_copy(fake->request_ctx, chbind->username));
                fr_pair_append(&fake->request_pairs, vp);
        }