Skip to content

plugins types BUGFIX instance-identifier required instance error code - #2613

Open
lamestllama wants to merge 1 commit into
CESNET:develfrom
lamestllama:fix/instance-identifier-required-validation-code
Open

lamestllama wants to merge 1 commit into
CESNET:develfrom
lamestllama:fix/instance-identifier-required-validation-code

Conversation

@lamestllama

Copy link
Copy Markdown

What

lyplg_type_validate_tree_instanceid() in src/plugins_types/instanceid.c now returns LY_EVALID when a required instance-identifier target does not exist, with the existing error item (LYVE_DATA, app-tag instance-required, message Invalid instance-identifier "..." value - required instance not found.). Before, it passed on the return value of ly_path_eval(), which is always LY_ENOTFOUND on failure. The leafref plugin already uses LY_EVALID for the same situation (src/plugins_types/leafref.c).

Why

A missing required target is invalid data. RFC 7950, section 9.9.3: "If "require-instance" is "true", it means that the instance being referred to MUST exist for the data to be valid." log.h sets the validation code together with LY_EVALID, and the error item already carries LYVE_DATA; only the return code differed.

The code also changed the behaviour of LYD_VALIDATE_MULTI_ERROR: LY_VAL_ERR_GOTO() in validation.c continues only after LY_EVALID, so validation stopped at the instance-identifier error and the errors after it were lost. With this schema:

leaf t {
  type string;
}
leaf lr {
  type leafref {
    path "/ri:t";
  }
}
leaf ii {
  type instance-identifier;
}

and the data <lr>x</lr><ii>/ri:t</ii>, multi-error validation returned 5 with only the instance-identifier error; it now returns 7 with both errors.

Callers checked: ly_path_eval() returns only LY_SUCCESS or LY_ENOTFOUND, so no other error is masked. The union plugin tries the next member type after any failure of a member, whatever the code (union_find_type()), and then reports LY_EVALID. lyd_value_validate_incomplete(), lyd_value_validate3() and their callers (validation.c, path.c, xpath.c, tree_schema_common.c) treat any non-zero code as a failure and do not test for LY_ENOTFOUND. The only code that relied on it is in the unit tests: five expectations in tests/utests/types/instanceid.c and one in tests/utests/extensions/test_structure.c, updated to LY_EVALID.

Fixes #2608

Test

  • New test_require_instance in tests/utests/data/test_validation.c: a missing leafref target and a missing instance-identifier target are each refused with LY_EVALID and the instance-required app-tag, and with LYD_VALIDATE_MULTI_ERROR both errors are reported.
  • test_data_xml in tests/utests/types/instanceid.c and test_parse in tests/utests/extensions/test_structure.c now expect LY_EVALID.

Before the fix (updated tests, unchanged library): utest_validation fails test_require_instance (22 of 23 pass), utest_instanceid fails test_data_xml (2 of 3) and utest_structure fails test_parse (4 of 5). After the fix, all three pass, and the whole ctest run passes (69 of 69; Debug build, GCC 13.3, aarch64).

A missing required instance-identifier target returned LY_ENOTFOUND
from ly_path_eval() instead of LY_EVALID, unlike a leafref, so
multi-error validation also stopped at this error.

Fixes CESNET#2608
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant