]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
internal-decode: Allow decoding of empty groups (groups with no children)
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sun, 11 Jan 2026 10:16:38 +0000 (10:16 +0000)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sun, 11 Jan 2026 10:16:45 +0000 (10:16 +0000)
src/protocols/internal/decode.c
src/tests/unit/protocols/internal/decode.txt

index c76edc7c63c1688aa51bc00fb20633d6eb21c6ac..9d6324ea0a8d18a5d0426903c5db0d757d220739 100644 (file)
@@ -121,7 +121,7 @@ static ssize_t internal_decode_pair(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dic
         *                           field (allows for future extensions).
         *
         * 0                   1                   2                   3
-        * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1kk
+        * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
         * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
         * |tlen |llen |t|e|   Type (min)  |  Length (min) | value...
         * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
@@ -253,8 +253,13 @@ static ssize_t internal_decode_pair(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dic
                                return fr_pair_decode_slen(slen, fr_dbuff_start(&work_dbuff), fr_dbuff_current(&work_dbuff));
                        }
                }
+               /*
+                *      It's ok for this function to return 0
+                *      we can have empty groups (i.e. groups
+                *      with no children)
+                */
                slen = internal_decode_structural(ctx, out, da, &work_dbuff, decode_ctx);
-               if (slen <= 0) goto error;
+               if (slen < 0) goto error;
                break;
 
        default:
index 47cde44754d6091d8e5af716dffef08489f4371b..0acf2827e31d66f0f849b7657bad023e06c8d749 100644 (file)
@@ -37,6 +37,10 @@ match User-Name = "0123456789012345678901234567890123456789012345678901234567890
 returned
 match 304
 
+# Decode an empty grouping attribute (this is a regression test)
+decode-pair 00 1a 04 20 2c 50 00
+match Vendor-Specific = { FreeRADIUS = { } }
+
 #
 #  Edge cases
 #
@@ -77,4 +81,4 @@ match -2
 #
 
 count
-match 40
+match 42