Skip to content

Commit

Permalink
allow deferred siblings
Browse files Browse the repository at this point in the history
  • Loading branch information
alandekok committed Nov 11, 2024
1 parent 406abe1 commit 2074195
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
10 changes: 4 additions & 6 deletions src/lib/util/dict_tokenize.c
Original file line number Diff line number Diff line change
Expand Up @@ -1418,16 +1418,14 @@ static int dict_read_process_member(dict_tokenize_ctx_t *ctx, char **argv, int a

previous = dict_attr_child_by_num(ctx->stack[ctx->stack_depth].da,
ctx->stack[ctx->stack_depth].member_num);
if (!previous) {
fr_strerror_const("Failed to find previous MEMBER");
goto error;
}

/*
* Check that the previous bit field ended on a
* byte boundary.
*
* Note that the previous attribute might be a deferred TLV, in which case it doesn't
* exist. That's fine.
*/
if (previous->flags.extra && (previous->flags.subtype == FLAG_BIT_FIELD)) {
if (previous && previous->flags.extra && (previous->flags.subtype == FLAG_BIT_FIELD)) {
/*
* This attribute is a bit field. Keep
* track of where in the byte we are
Expand Down
14 changes: 6 additions & 8 deletions src/lib/util/dict_validate.c
Original file line number Diff line number Diff line change
Expand Up @@ -508,25 +508,23 @@ bool dict_attr_flags_valid(fr_dict_t *dict, fr_dict_attr_t const *parent,
fr_dict_attr_t const *sibling;

sibling = fr_dict_attr_child_by_num(parent, (attr) - 1);
if (!sibling) {
fr_strerror_printf("Child \"%s\" of 'struct' attribute \"%s\" MUST be "
"numbered consecutively %u.",
name, parent->name, attr);
return false;
}

/*
* sibling might not exist, if it's a deferred 'tlv clone=...'
*/

/*
* Variable sized elements cannot have anything after them in a struct.
*/
if (!sibling->flags.length && !sibling->flags.is_known_width) {
if (sibling && !sibling->flags.length && !sibling->flags.is_known_width) {
fr_strerror_const("No other field can follow a struct MEMBER which is variable sized");
return false;
}

/*
* The same goes for arrays.
*/
if (sibling->flags.array) {
if (sibling && sibling->flags.array) {
fr_strerror_const("No other field can follow a struct MEMBER which is 'array'");
return false;
}
Expand Down

0 comments on commit 2074195

Please sign in to comment.