Skip to content

Conversation

crisrss
Copy link

@crisrss crisrss commented Jul 1, 2025

Potential fix for https://github.com/SolidifyDemo/ghas-vulnerable-c-cpp-template/security/code-scanning/11

To fix the issue, we need to ensure that the function never returns a pointer to stack-allocated memory. This can be achieved by dynamically allocating memory for msg_ctxt_id in all cases, regardless of the configuration. This way, the lifetime of the memory extends beyond the function's scope, and the returned pointer remains valid.

Specifically:

  1. Replace the stack-allocated array msg_ctxt_id (line 218) with a dynamically allocated buffer using malloc.
  2. Ensure that the dynamically allocated memory is freed if it is not returned (e.g., when translation != msg_ctxt_id).
  3. Update the code to handle memory allocation failures gracefully.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

…ed memory

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant