Repository navigation
data REFACTOR build strings with measured, bounded appends - #2625
Merged
Merged
Conversation
michalvasko
requested changes
Nov 9, 2026
michalvasko
left a comment
Member
There was a problem hiding this comment.
Please fix the conflicts and the few issues. Otherwise seems fine, thanks.
The XPath string cast, concat() and the JSON predicate, lyd_path(), the LYB feature check and the CBOR number conversion grew strings by summing each length by hand and writing with sprintf()/strcpy()/strcat(). The sums are correct today but each has to keep matching its format string, and these paths format values that come from parsed data. Measure the formatted output and write it bounded instead, as CESNET#2591 did for the type plugins. Output is unchanged. - xpath.c: new cast_string_append() measures with vsnprintf() and keeps the step growth of the former cast_string_realloc(), now inlined into it. concat() and the predicate builder use ly_append_str(). - tree_data.c: new lyd_path_str_append() with the former lyd_path_str_enlarge() inlined, so a static buffer still returns LY_EINCOMPLETE. - parser_lyb.c: feature lists use ly_append_str(); the revision string uses snprintf(). This also fixes lyb_check_mod_features() returning LY_SUCCESS when allocating the error message failed, which accepted mismatched features. - parser_cbor.c, parser_common.c: snprintf() bounded by the allocation, strdup() instead of malloc()+strcpy().
aravindor
force-pushed
the
refactor-bounded-strings
branch
from
November 9, 2026 16:46
9b18999 to
650a932
Compare
Author
|
Thanks for the review. Updated:
On your suggestion to fold this into |
michalvasko
approved these changes
Nov 10, 2026
Member
|
Looks okay now, thanks. |
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.
The XPath string cast,
concat()and the JSON predicate builder,lyd_path(), the LYB feature check and the CBOR number conversion grow strings by summing each length by hand and then writing withsprintf()/strcpy()/strcat(). Every one of those sums has to keep matching its format string, and these paths format values that come from parsed data. They are all correct today; this removes the hand-sized math so it cannot drift, the same way #2591 did for the type plugins.cast_string_append()measures the text withvsnprintf()and writes it bounded, keeping the step growth ofcast_string_realloc().concat()and the predicate builder use the existingly_append_str().lyd_path_str_append()does the same on top oflyd_path_str_enlarge(), so a static buffer still returnsLY_EINCOMPLETE. The position predicate no longer needs a temporaryasprintf().ly_append_str(). This also fixeslyb_check_mod_features()returningLY_SUCCESSwhen allocating the error message failed, which accepted data with mismatched features. The revision string usessnprintf().snprintf()bounded by the allocation, andstrdup()in place ofmalloc()+strcpy().Output is unchanged. Built on
develwith-fsanitize=address,undefined; the full test suite passes (71/71), no sanitizer reports, andmake format-checkis clean.