Merged
Conversation
… `print_netdata_double` for clarity and maintainability.
Contributor
There was a problem hiding this comment.
1 issue found across 2 files
Confidence score: 4/5
- This PR looks safe to merge overall, with only a minor edge-case risk noted.
- In
src/libnetdata/libnetdata.c, iffmtis NULL the guard returns without null-terminatingdst, which could leave callers reading stale/unterminated data after a failure. - Pay close attention to
src/libnetdata/libnetdata.c- ensuredstis set to an empty string whenfmtis NULL.
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="src/libnetdata/libnetdata.c">
<violation number="1" location="src/libnetdata/libnetdata.c:66">
P2: Guarding against NULL fmt returns without null-terminating dst, so callers may read stale/unterminated data after a failure. Ensure dst is set to an empty string when fmt is NULL.</violation>
</file>
Architecture diagram
sequenceDiagram
participant Eval as Expression Evaluator
participant Utils as Eval Utils
participant Lib as libnetdata
participant Buf as Buffer
Note over Eval,Buf: Expression Evaluation Flow (e.g., eval_variable)
Eval->>Utils: print_parsed_as_constant(out, value)
rect rgb(23, 37, 84)
Note right of Utils: NEW: Use standard double formatter
Utils->>Lib: print_netdata_double(b, value)
Lib->>Lib: vsnprintfz(dst, n, fmt, args)
alt NEW: Input Validation
Note right of Lib: Check if dst, fmt, or n is NULL/zero
Lib-->>Lib: Return 0 early if invalid
else Valid Inputs
Lib->>Lib: vsnprintf(dst, n, fmt, args)
Lib-->>Lib: Force null-termination: dst[n-1] = '\0'
end
Lib-->>Utils: Formatted string in stack buffer 'b'
end
Utils->>Buf: buffer_strcat(out, b)
Buf-->>Utils: String appended
Utils-->>Eval: Completion
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR prevents a potential crash in expression evaluation by improving the robustness of numeric formatting functions.
Changes:
- Added null pointer checks in
vsnprintfz()to prevent crashes when called with invalid arguments - Refactored
print_parsed_as_constant()to use the sharedprint_netdata_double()function with a larger buffer (DOUBLE_MAX_LENGTH = 512 bytes) instead of custom formatting with a 101-byte buffer
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/libnetdata/libnetdata.c | Added null checks for dst, fmt, and n parameters in vsnprintfz() to prevent crashes |
| src/libnetdata/eval/eval-utils.c | Replaced custom double formatting logic with print_netdata_double(), using DOUBLE_MAX_LENGTH buffer to handle very large numbers safely |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
thiagoftsm
approved these changes
Feb 20, 2026
Contributor
thiagoftsm
left a comment
There was a problem hiding this comment.
PR is working as expected locally. LGTM!
stelfrag
added a commit
to stelfrag/netdata
that referenced
this pull request
Mar 16, 2026
* Refactor double formatting in eval-utils.c: replace custom logic with `print_netdata_double` for clarity and maintainability. * Add null checks for `dst` and `fmt` in `vsnprintfz` to prevent potential issues * Add null check for `fmt` in `vsnprintfz` and ensure `dst` is properly initialized (cherry picked from commit 22962fc)
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.
Summary
Prevent possible crash
Summary by cubic
Fixes a potential crash during expression evaluation by using the shared double formatter and adding safety checks in vsnprintfz. Also simplifies number formatting for consistency.
Written for commit 1fe5c57. Summary will update on new commits.