Repository navigation
Conversation
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 one has to keep matching its format string, and these paths format values that come from parsed data. Measure the formatted output with vsnprintf() and write it bounded instead, as CESNET#2591 did for the type plugins. Output is unchanged. - xpath.c: new cast_string_append() keeps the step growth of cast_string_realloc(); concat() and the predicate builder use ly_append_str(). - tree_data.c: new lyd_path_str_append() on top of lyd_path_str_enlarge(), so static buffers still return 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().
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.