Skip to content

plugins types REFACTOR build strings with ly_append_str - #2591

Merged
michalvasko merged 1 commit into
CESNET:develfrom
vera-rubin:fix/types-ly-append-str
Oct 19, 2026
Merged

michalvasko merged 1 commit into
CESNET:develfrom
vera-rubin:fix/types-ly-append-str

Conversation

@vera-rubin

Copy link
Copy Markdown

The bits, identityref, instance-identifier-keys, xpath1.0 and union type plugins grow strings by summing each realloc() size by hand and then writing with sprintf() or strcpy(). Every one of those sums has to match its format string. This switches them to the existing ly_append_str() helper, which sizes the buffer from the formatted output itself. The IPv4/IPv6 zone suffix is now printed with snprintf() bounded by the allocated size.

ly_append_str() also gains printf format checking and checks for vsnprintf() failure and size overflow. ly_strcat() now checks for vasprintf() failure and does not leak on realloc() failure.

All tests pass, and one new test covers the multi-base identityref error message.

If it lands, we may submit it to Google's Patch Rewards program, and we'd be glad to share any reward with the maintainers.

— ChipLab

The bits, identityref, instance-identifier-keys, xpath1.0 and union
type plugins grew their strings by computing each realloc() size by
hand and then writing into the buffer with sprintf() or strcpy(). Use
ly_append_str() instead, which sizes the buffer from the formatted
output itself, so no length computation has to be kept in sync with
the format string. The IPv4/IPv6 zone suffix is now printed with
snprintf() bounded by the allocated size.

ly_append_str() now checks for vsnprintf() failure and size overflow
and is declared with printf format checking. ly_strcat() checks for
vasprintf() failure and no longer leaks on realloc() failure.

Printed values and error messages are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@michalvasko

Copy link
Copy Markdown
Member

Thanks, looks good.

@michalvasko
michalvasko merged commit 1f00f0c into CESNET:devel Oct 19, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants