Fix for CWE-122: Heap-based Buffer Overflow #3
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.
🐕 Corgea issued a PR to fix a vulnerability found in lib/libwasm.c.
It is CWE-122: Heap-based Buffer Overflow that has a severity of 🔴 Critical.
🪄 Fix explanation
The fix mitigates a heap overflow by validating the parameter count before allocation and dynamically allocating the params buffer only for the declared count, preventing overruns beyond the maximum limit of 10 parameters.
- Removed fixed-size allocation "calloc(10, sizeof(WasmValueType))", which risked overflow if actual param_count was larger.
- Added a check "if (entry->param_count > 10) goto parse_error;" to enforce WebAssembly’s maximum parameter limit.
- Allocated "entry->params" dynamically with size based on "entry->param_count" to fit exactly the required parameters.
- Added NULL check after allocation to handle memory failures safely, redirecting to "parse_error" if allocation fails.
💡 Important Instructions
Ensure that the
parse_errorlabel correctly frees any previously allocated resources to avoid memory leaks during error handling.See the issue and fix in Corgea.