From: Alan T. DeKok Date: Tue, 12 Nov 2024 20:19:17 +0000 (-0500) Subject: fixed-size structs can't contain fields of unknown length X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=405bb3c00cce1efbce7e96d475650e8bd624cfcd;p=thirdparty%2Ffreeradius-server.git fixed-size structs can't contain fields of unknown length --- diff --git a/src/lib/util/dict_tokenize.c b/src/lib/util/dict_tokenize.c index 08ce533fcae..3989c86538d 100644 --- a/src/lib/util/dict_tokenize.c +++ b/src/lib/util/dict_tokenize.c @@ -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; }