Repository navigation
Conversation
michalvasko
left a comment
There was a problem hiding this comment.
Please fix the conflicts and the few issues. Otherwise seems fine, thanks.
| } | ||
|
|
||
| /* the terminating zero is overwritten, so len more bytes are needed */ | ||
| LY_CHECK_RET(cast_string_realloc(ctx, len, str, used, size)); |
There was a problem hiding this comment.
Seems this is the only use of cast_string_realloc() now so you can just inline the function here. Actually, if you just add context as (an optional) parameter to ly_append_str(), you can remove this function altogether.
| return LY_SUCCESS; | ||
| } | ||
|
|
||
| static LY_ERR cast_string_append(const struct ly_ctx *ctx, char **str, uint32_t *used, uint32_t *size, |
There was a problem hiding this comment.
Please put all local prototypes at the file beginning.
| return LY_ESYS; | ||
| } | ||
|
|
||
| LY_CHECK_RET(lyd_path_str_enlarge(buffer, buflen, *bufused + len, is_static)); |
There was a problem hiding this comment.
Again, function no longer used, inline here.
| } | ||
|
|
||
| static LY_ERR lyd_path_str_append(char **buffer, size_t *buflen, size_t *bufused, ly_bool is_static, | ||
| const char *format, ...) _FORMAT_PRINTF(5, 6); |
There was a problem hiding this comment.
Please move at the beginning of the file.
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().
9b18999 to
650a932
Compare
|
Thanks for the review. Updated:
On your suggestion to fold this into |
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.