Conversation
…ilters Escape quotes/backslashes in Redis Lua filter keys and must/when predicates so special characters cannot break Lua scripts. Signed-off-by: Aditi Gupta <rasheegupta.11@gmail.com>
|
|
|
/azp run |
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
Libyang uses single quotes unless the value itself contains a single quote. Always wrapping keys in single quotes breaks path parsing for those values. Signed-off-by: Aditi Gupta <rasheegupta.11@gmail.com>
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of PR
Summary:
CVL interpolates Redis keys and YANG values into generated Lua and into
libyang3 list-key path predicates. Values that contain
',\, or%can break those strings, so delete-dependency lookup, must/when evaluation,
and list-node creation fail or match the wrong entries.
This change:
\and'before interpolating keys into delete-dependency Luafilters in
GetDepDataForDelete().string.find(plain=true) so%is not treated as a Luapattern character in leaf-list matching.
xpath engine patch.
unless the value itself contains
', then double quotes(
formatLyPredicateValue()used byAddListNode()).Type of change
Back port request
Tested branch
Test result
Added / updated CVL unit tests:
TestGetDepDataForDeleteSpecialKeyChars— keys containing',\,%TestGetDepDataForDeleteLeafListPatternChars— leaf-list values with Luapattern characters
TestValidateEditConfig_Must_Predicate_Escape_SingleQuoteTestValidateEditConfig_Must_Predicate_Escape_BackslashTestValidateEditConfig_When_Predicate_Escape_SingleQuoteTestValidateEditConfig_When_Predicate_Escape_BackslashApproach
What is the motivation for this PR?
GetDepDataForDelete()embeds Redis key values into a Lua script usingfmt.Sprintfandstring.find. Unescaped quotes break the Lua string, andunescaped
%is treated as a pattern. must/when predicates had the sameissue when config values were written into Lua predicate strings.
AddListNode()always wrapped list-key values in single quotes(
[key='value']). Libyang3 uses double quotes when the value contains',so keys with a single quote fail path parsing.
That can cause:
',\, or%'How did you do it?
In
cvl/cvl_api.go(GetDepDataForDelete()):\and'in the key before building the Lua filter script.string.find(..., 1, true)so the search is a plain string match.In
patches/xpath.patch:\and'when assigningSFilter.Predicatefrom config values(
currentQuery,constantQuery, andchildQueryevaluation).In
cvl/internal/yparser/ly_path.goandcvl/internal/yparser/yparser.go:formatLyPredicateValue()and use it inAddListNode()so list-keypredicates match libyang quoting (
'value'or"value").No change to Redis data; only generated Lua and libyang path strings are
sanitized.
How did you verify/test it?
CVL Go unit tests covering:
'or\Existing
TestGetDepDataForDeletecoverage is unchanged.Any platform specific information?
No. Generic CVL / Lua / libyang3 path behavior.
Supported testbed topology if it's a new test case?
N/A
Documentation
N/A