fix(foundation): properly escape JSON control characters as \u00XX#527
Open
Ravandevil25 wants to merge 1 commit into
Open
fix(foundation): properly escape JSON control characters as \u00XX#527Ravandevil25 wants to merge 1 commit into
Ravandevil25 wants to merge 1 commit into
Conversation
Signed-off-by: Saurav Kumar <sauravsk2507@gmail.com>
Owner
|
Thanks @Ravandevil25 — the control-character |
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.
Describe the bug
In
src/foundation/str_util.c, thecbm_json_escapefunction was handling control characters< 0x20by completely skipping them instead of properly escaping them as\u00XX. Thejson_escaped_lenfunction mirrored this logic. While this avoided buffer overflows, it silently stripped control characters, resulting in an invalid JSON representation of the actual data.Impact
Silently stripping control characters from strings mutates the data. If a file path, git branch, or code snippet contained unusual control characters, they were silently erased from the MCP JSON response rather than safely serialized.
Fix
cbm_json_escapeto safely format control characters as\u00XXusingsnprintf(buf + pos, 7, "\\u%04x", c).#include <stdio.h>tostr_util.cforsnprintf.json_escaped_lento correctly reserve 6 bytes (len += 6) for unhandled control characters, aligning the buffer sizing with the formatting string.Local tests and strict compilation (
-Wall -Werror) pass successfully.