Repository navigation
schema diff, types, parsers REFACTOR bound the remaining string writes - #2628
Merged
Merged
Conversation
michalvasko
requested changes
Nov 11, 2026
The schema diff tree, the decimal64 / ipv4-prefix / ipv6-prefix canonical value printers, the date/time helpers and lysc_path_until() still built strings with sprintf()/strcpy() into buffers sized by hand. Each buffer is already large enough, but the writes were unbounded. Convert them to snprintf() bounded by the buffer (sizeof or the allocation size). Output is unchanged. The YANG and YIN pattern modifier parsers duplicated the pattern with malloc() + strcpy(), use strdup() there. The YIN revision-date parser copies LY_REV_SIZE bytes, the length lys_check_date() has just verified.
aravindor
force-pushed
the
harden-remove-unbounded-str
branch
from
November 13, 2026 17:09
cc178f6 to
2b69bd2
Compare
Author
|
Thanks for the review. Updated:
What is left is the |
michalvasko
approved these changes
Nov 16, 2026
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.
This is a hardening change that bounds the remaining
sprintf()writes insrc/, following the same approach as #2625.What changes
sprintf(...)becomessnprintf(..., <bound>, ...)at every remainingcall site, where
<bound>is the real capacity of the target:sizeof buffor stack buffers,LY_NUMBER_MAXLENfor the numberbuffers allocated with that size.
Files:
schema_diff_tree.c,plugins_types/decimal64.c,plugins_types/ipv4_address_prefix.c,plugins_types/ipv6_address_prefix.c,tree_data_common.c.tree_schema.c:lysc_path_until()writes "/" withsnprintf()boundedby the caller's buffer length instead of
strcpy().parser_yang.candparser_yin.c: the pattern modifier parsers duplicatethe pattern with
strdup()instead ofmalloc()+strcpy().parser_yin.c: the revision-date parser copiesLY_REV_SIZEbytes, thelength
lys_check_date()has just verified, instead ofstrcpy().After review, the
strcpy()calls inplugins_exts/schema_mount.candvalidation.cstay as they are.Not a bug fix
The current size math at these sites is already correct: the formatted
output fits the target in every reachable case, so this does not fix any
observable overflow. It is defense in depth. The value is that the bound
is now stated in the code instead of being an invariant you have to
re-derive.
Testing
Debugbuild with-fsanitize=address,undefined, 0 warnings.ctest72/72 pass under ASan + UBSan, including theformatcheck.