Skip to content

Conversation

@AndresMaqueo
Copy link
Owner

Potential fix for https://github.com/AndresMaqueo/codeql-coding-standards/security/code-scanning/67

To fix the problem, you should replace the use of gets on line 37 with a safer alternative. The recommended approach is to use fgets, which allows you to specify the maximum number of characters to read into the buffer, preventing buffer overflow. Since there is no buffer passed to gets in the provided code (reflecting a mistaken usage), the code should be updated to correctly allocate a buffer and call fgets instead. You need to declare a buffer with a fixed size, then use fgets(buffer, sizeof(buffer), stdin) to read from standard input. Update the function's implementation in f6 and remove or comment out the incorrect extern char *gets(FILE *stream); declaration if necessary.

No new imports are required since <stdio.h> is already included.


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

This autofix replaces the unsafe and obsolete 'gets()' function with a safer 'fgets()' implementation to prevent potential buffer overflow vulnerabilities. 
The fix allocates a buffer with a defined size and reads input securely from standard input using fgets(buf, sizeof(buf), stdin). 
Additionally, the obsolete declaration 'extern char *gets(FILE *stream);' was removed to ensure compliance with C11 and MISRA guidelines.
No functional changes were introduced apart from enhancing security and standards compliance.

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.

2 participants