π‘οΈ Sentinel: Fix excessive stack usage in JSON escaping - #175
π‘οΈ Sentinel: Fix excessive stack usage in JSON escaping#175rgerhards wants to merge 1 commit into
Conversation
Reduced the stack buffer size in `jsonAddVal_escaped` (runtime/msg.c) from 100KB to 4KB to mitigate potential stack overflow risks. The function already implements a fallback to heap allocation for larger buffers, so functionality is preserved. Added a regression test `tests/json-long-string.sh` to verify correct JSON escaping for strings exceeding the new stack buffer size. Co-authored-by: Jules Agent <jules@agent.com> Co-authored-by: rgerhards <1482123+rgerhards@users.noreply.github.com>
|
π Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a π emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Summary of ChangesHello @rgerhards, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical vulnerability where a large stack allocation could lead to a Denial of Service. By significantly reducing the stack buffer size and relying on an existing heap allocation fallback for larger data, the system's stability is improved. A new test case has been added to ensure the fix functions as expected without introducing regressions for long string processing. Highlights
π§ New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with π and π on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request effectively addresses a denial-of-service vulnerability caused by excessive stack allocation. Reducing the buffer in jsonAddVal_escaped from 100KB to 4KB is a solid fix, especially since the function already has a fallback mechanism to heap allocation for larger data. The inclusion of a new regression test, tests/json-long-string.sh, is excellent as it ensures that the fix doesn't introduce regressions for large string processing. I have one minor suggestion to improve code maintainability.
| unsigned char nc; | ||
| int j; | ||
| uchar wrkbuf[100000]; | ||
| uchar wrkbuf[4096]; |
There was a problem hiding this comment.
There was a problem hiding this comment.
1 issue found across 4 files
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="tests/json-long-string.sh">
<violation number="1" location="tests/json-long-string.sh:36">
P2: Rule violated: **Code Quality Guard**
Ad-hoc validation with redundant checks violates testbench policy. Per `tests/AGENTS.md`: "Prefer harness helpers such as `cmp_exact`, `command_deny`, and `require_plugin` over ad-hoc shell to keep diagnostics uniform."
The `[ ! -f $RSYSLOG_OUT_LOG ]` check is entirely redundant with the `[ ! -s $RSYSLOG_OUT_LOG ]` check that follows (a file with size > 0 necessarily exists). Additionally, `$RSYSLOG_OUT_LOG` must be quoted in all shell expansions. This pattern of redundant guards with unquoted variables is a slop indicator (AI_PROBABILITY: high, POLICY_COMPLIANCE: low, SLOP_SCORE: elevated).</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
| shutdown_when_empty | ||
| wait_shutdown | ||
|
|
||
| if [ ! -f $RSYSLOG_OUT_LOG ]; then |
There was a problem hiding this comment.
P2: Rule violated: Code Quality Guard
Ad-hoc validation with redundant checks violates testbench policy. Per tests/AGENTS.md: "Prefer harness helpers such as cmp_exact, command_deny, and require_plugin over ad-hoc shell to keep diagnostics uniform."
The [ ! -f $RSYSLOG_OUT_LOG ] check is entirely redundant with the [ ! -s $RSYSLOG_OUT_LOG ] check that follows (a file with size > 0 necessarily exists). Additionally, $RSYSLOG_OUT_LOG must be quoted in all shell expansions. This pattern of redundant guards with unquoted variables is a slop indicator (AI_PROBABILITY: high, POLICY_COMPLIANCE: low, SLOP_SCORE: elevated).
Prompt for AI agents
Check if this issue is valid β if so, understand the root cause and fix it. At tests/json-long-string.sh, line 36:
<comment>Ad-hoc validation with redundant checks violates testbench policy. Per `tests/AGENTS.md`: "Prefer harness helpers such as `cmp_exact`, `command_deny`, and `require_plugin` over ad-hoc shell to keep diagnostics uniform."
The `[ ! -f $RSYSLOG_OUT_LOG ]` check is entirely redundant with the `[ ! -s $RSYSLOG_OUT_LOG ]` check that follows (a file with size > 0 necessarily exists). Additionally, `$RSYSLOG_OUT_LOG` must be quoted in all shell expansions. This pattern of redundant guards with unquoted variables is a slop indicator (AI_PROBABILITY: high, POLICY_COMPLIANCE: low, SLOP_SCORE: elevated).</comment>
<file context>
@@ -0,0 +1,57 @@
+shutdown_when_empty
+wait_shutdown
+
+if [ ! -f $RSYSLOG_OUT_LOG ]; then
+ error_exit 1
+fi
</file context>
π‘οΈ Sentinel: [MEDIUM] Fix excessive stack usage in JSON escaping
π¨ Severity: MEDIUM
π‘ Vulnerability:
jsonAddVal_escapedallocated 100KB on the stack, posing a DoS risk via stack overflow.π― Impact: Crash/Denial of Service in deep call stacks or constrained environments.
π§ Fix: Reduced stack buffer to 4KB; existing malloc fallback handles larger data.
β Verification: New regression test
tests/json-long-string.shconfirms large strings are still processed correctly.PR created automatically by Jules for task 3361815841138830520 started by @rgerhards