Add unit tests for jsonw_pretty and fix buffer overflow vulnerabilities - #284
Open
gotaku3737-sketch wants to merge 13 commits into
Open
Add unit tests for jsonw_pretty and fix buffer overflow vulnerabilities#284gotaku3737-sketch wants to merge 13 commits into
gotaku3737-sketch wants to merge 13 commits into
Conversation
Implemented a new unit test suite in src/jsonw_test.c to verify the functionality of the jsonw_pretty function in json_writer.c. The tests cover: - Default compact output (pretty-printing off) - Formatted output (pretty-printing on) - Toggling pretty-printing mid-stream Updated src/Makefile to include a 'test' target for compiling and running the unit tests, and updated the 'clean' target to remove the test binary. The tests use open_memstream to capture and verify the JSON output. Co-authored-by: gotaku3737-sketch <244136235+gotaku3737-sketch@users.noreply.github.com>
…-writer-6286810798765254243 🧪 [testing improvement] Add unit tests for jsonw_pretty
This commit replaces the manual memory allocation and unsafe use of strcat with asprintf in do_prog. Previously, a buffer was allocated with malloc(strlen(*argv) + 2) and then filled using strcat. While the size was technically correct, using strcat is generally discouraged for security and maintainability. The new implementation uses asprintf, which is safer as it handles allocation and formatting in a single step, reducing the risk of buffer overflows or off-by-one errors during manual size calculation. 🎯 What: Potential buffer overflow in do_prog when appending a slash to the program type.⚠️ Risk: Manual buffer management and strcat can lead to vulnerabilities if size calculations are incorrect or modified. 🛡️ Solution: Use asprintf to safely allocate and format the string. Co-authored-by: gotaku3737-sketch <244136235+gotaku3737-sketch@users.noreply.github.com>
…rog-strcat-4091783086360426996 🔒 [security fix] Fix Buffer Overflow in do_prog via strcat
…g ops Replaced unbounded string operations (`sprintf`, `strcpy`, `strcat`) with their safer, bounded equivalents (`snprintf`) across core source files (`src/prog.c`, `src/gen.c`, `src/feature.c`, `src/tracelog.c`, `src/kernel/bpf/disasm.c`, `src/main.c`). This implements a defense-in-depth approach to mitigate potential buffer overflows. Co-authored-by: gotaku3737-sketch <244136235+gotaku3737-sketch@users.noreply.github.com>
…-fix-14531536299354862931 🛡️ Sentinel: [HIGH] Fix potential buffer overflows using bounded string operations
…parsing kallsyms 🚨 Severity: HIGH 💡 Vulnerability: The `sscanf` call in `src/xlated_dumper.c` used unbounded `%s` format specifiers to parse `/proc/kallsyms`. 🎯 Impact: An unusually long kernel symbol or module name could overflow the stack-allocated buffers `sym->name` and `sym->module`, leading to a buffer overflow and potential memory corruption. 🔧 Fix: Added explicit length limits to the `sscanf` format string (`%255s` and `%63[^]]`) matching the struct sizes defined in `xlated_dumper.h`. ✅ Verification: Ran `make -C src bpftool` and verified tests pass. Co-authored-by: gotaku3737-sketch <244136235+gotaku3737-sketch@users.noreply.github.com>
…er-overflow-11300022512747804490 🛡️ Sentinel: [HIGH] Fix buffer overflow vulnerability in sscanf
This commit addresses a critical vulnerability in `src/jit_disasm.c` where an out-of-bounds memory read and write could occur during string manipulation. 🚨 Severity: CRITICAL 💡 Vulnerability: The loop responsible for stripping trailing spaces from the formatted JSON string decremented the string index without checking if it was within valid bounds (e.g., `< 0`). 🎯 Impact: If the string was empty or contained only spaces, the index could reach `-1`, leading to memory corruption and undefined behavior. 🔧 Fix: Added a boundary check `i >= 0` to the while loop condition to ensure the index does not underflow. ✅ Verification: Tested against empty strings and strings with only spaces, and verified the build and json_writer tests pass. Co-authored-by: gotaku3737-sketch <244136235+gotaku3737-sketch@users.noreply.github.com>
…603583010440029 🛡️ Sentinel: [CRITICAL] Fix out-of-bounds memory access in jit_disasm.c
…_dumper.c Co-authored-by: gotaku3737-sketch <244136235+gotaku3737-sketch@users.noreply.github.com>
…ed-format-string-5652547563540882573 🛡️ Sentinel: [CRITICAL] Fix uninitialized VLA format string
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.
No description provided.