Fix memory leaks, buffer overflows, and buffer overread#291
Merged
dledda-r7 merged 5 commits intorapid7:masterfrom Feb 3, 2026
Merged
Fix memory leaks, buffer overflows, and buffer overread#291dledda-r7 merged 5 commits intorapid7:masterfrom
dledda-r7 merged 5 commits intorapid7:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes memory leaks, buffer overflows, and a buffer overread vulnerability across multiple files in the mettle codebase.
Changes:
- Fixed realloc memory leak pattern in TLV packet functions
- Replaced unsafe sprintf calls with snprintf to prevent buffer overflows
- Added proper cleanup on error paths to prevent memory leaks
- Fixed buffer overread in console command parsing
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| mettle/src/tlv.c | Fixed realloc memory leaks in tlv_packet_add_child_raw and tlv_packet_add_raw by storing realloc result in new pointer and freeing original on failure |
| mettle/src/stdapi/sys/memory.c | Added memory cleanup for read_str and matches on realloc failure; replaced sprintf with snprintf to prevent buffer overflow |
| mettle/src/stdapi/audio/linux_output.c | Fixed memory leak by using goto cleanup pattern to ensure ctx->buffer and ctx are always freed on error paths |
| mettle/src/stdapi/audio/linux_mic.c | Added missing stdlib.h include; added cleanup for sound_device and proc_asound_pcm; replaced sprintf with snprintf |
| mettle/src/console.c | Fixed buffer overread by properly parsing command with whitespace skipping and validation before accessing module name |
| mettle/src/buffer_queue.c | Fixed memory leak by calling buffer_queue_drain_all before freeing queue to clean up all buffered data |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
|
@bcoles thanks, looks good! |
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.