]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
fixed-size structs can't contain fields of unknown length
authorAlan T. DeKok <aland@freeradius.org>
Tue, 12 Nov 2024 20:19:17 +0000 (15:19 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 13 Nov 2024 13:01:48 +0000 (08:01 -0500)
src/lib/util/dict_tokenize.c

index 08ce533fcaefe9d847a28a36fdffa4540058dba0..3989c86538da9cda9ce896fd862f4750f3c337f9 100644 (file)
@@ -1585,7 +1585,20 @@ static int dict_read_process_member(dict_tokenize_ctx_t *ctx, char **argv, int a
                /*
                 *      Add the size of this member to the parent struct.
                 */
-               ctx->stack[ctx->stack_depth].struct_size += da->flags.length;
+               if (ctx->stack[ctx->stack_depth].da->flags.length) {
+                       /*
+                        *      Fixed-size struct can't have MEMBERs of unknown sizes.
+                        */
+                       if (!da->flags.is_known_width) {
+                               fr_strerror_printf("'struct' %s has fixed size %u, but member %s is of unknown size",
+                                                  ctx->stack[ctx->stack_depth].da->name, ctx->stack[ctx->stack_depth].da->flags.length,
+                                                  argv[0]);
+                               return -1;
+                       }
+
+                       ctx->stack[ctx->stack_depth].struct_size += da->flags.length;
+
+               }
 
                /*
                 *      Check for overflow.
@@ -2442,8 +2455,8 @@ static int _dict_from_file(dict_tokenize_ctx_t *ctx,
                                 */
                                if (da->flags.length &&
                                    (ctx->stack[ctx->stack_depth].struct_size != da->flags.length)) {
-                                       fr_strerror_printf("MEMBERs of 'struct' %s do not exactly fill the fixed-size structure",
-                                                          da->name);
+                                       fr_strerror_printf("MEMBERs of %s struct[%u] do not exactly fill the fixed-size structure",
+                                                          da->name, da->flags.length);
                                        goto error;
                                }