diff options
| author | John Estabrook <jestabro@vyos.io> | 2025-12-08 21:24:59 -0600 |
|---|---|---|
| committer | John Estabrook <jestabro@vyos.io> | 2025-12-17 21:13:45 -0600 |
| commit | e87f921a3611c8054c0253dc78bfbc3f50ca6e28 (patch) | |
| tree | 4614446ff1a170eb9f150e443b818ba47f3103df /src/reference_tree.ml | |
| parent | 7904df55c5ae18c8b00460e26f44c78b80defd5c (diff) | |
| download | vyos1x-config-e87f921a3611c8054c0253dc78bfbc3f50ca6e28.tar.gz vyos1x-config-e87f921a3611c8054c0253dc78bfbc3f50ca6e28.zip | |
T8061: require strict check of existence in refpath
For use in reference_path_exists, add strict check in the utility that
forms the reference path from a config path.
Diffstat (limited to 'src/reference_tree.ml')
| -rw-r--r-- | src/reference_tree.ml | 63 |
1 files changed, 37 insertions, 26 deletions
diff --git a/src/reference_tree.ml b/src/reference_tree.ml index 9ed9692..a465a84 100644 --- a/src/reference_tree.ml +++ b/src/reference_tree.ml @@ -594,15 +594,26 @@ let get_completion_data reftree path = (* Convert from config path to reference tree path *) let refpath reftree path = - (* raises: - [Vytree.Nonexistent_path] from is_tag - *) + let check_existence p = + match p with + | [] -> false + | _ -> (Vytree.exists[@alert "-exn"]) reftree p + in let rec aux acc p = match acc, p with - | [], h :: tl -> aux (acc @ [h]) tl - | _, [h] -> if is_tag reftree acc then acc else acc @ [h] - | _, h :: h' :: tl -> if is_tag reftree acc then aux (acc @ [h']) tl - else aux (acc @ [h]) ([h'] @ tl) + | [], h :: tl -> + if check_existence [h] then aux [h] tl else [] + | _, [h] -> + if is_tag reftree acc then acc else + let p = acc @ [h] in + if check_existence p then p else [] + | _, h :: h' :: tl -> + if is_tag reftree acc then + let p = acc @ [h'] in + if check_existence p then aux p tl else [] + else + let p = acc @ [h] in + if check_existence p then aux p ([h'] @ tl) else [] | _, [] -> acc in aux [] path @@ -685,26 +696,26 @@ let potential_leaf_value rtree cpath = 'potential' tag value as final element of the path. *) let allowed_edit_level rtree path = - try - let refp = refpath rtree path - in - if Util.is_empty refp then - Error {|The "edit" command cannot be issued at an empty path|} - else - if is_tag rtree refp && not (potential_tag_value rtree path) - then - Error {|The "edit" command cannot be issued at the level of tag node|} - else - if potential_leaf_value rtree path - then - Error {|The "edit" command cannot be issued at the level of leaf value|} - else - if is_leaf rtree refp - then - Error {|The "edit" command cannot be issued at the level of leaf node|} - else Ok () - with Vytree.Nonexistent_path -> + if Util.is_empty path then + Error {|The "edit" command cannot be issued at an empty path|} + else + let refp = refpath rtree path + in + if Util.is_empty refp then Error {|The "edit" command cannot be issued at a non-existent path of the reference tree|} + else + if is_tag rtree refp && not (potential_tag_value rtree path) + then + Error {|The "edit" command cannot be issued at the level of tag node|} + else + if potential_leaf_value rtree path + then + Error {|The "edit" command cannot be issued at the level of leaf value|} + else + if is_leaf rtree refp + then + Error {|The "edit" command cannot be issued at the level of leaf node|} + else Ok () let get_ceil_data f reftree path = (* raises: |
