Skip to content

New Published Rules - dannytheway_personal.unbounded-copy-to-stack-buffer#3781

Open
semgrep-dev-pr-bot[bot] wants to merge 2 commits intodevelopfrom
semgrep-live-boL4Z
Open

New Published Rules - dannytheway_personal.unbounded-copy-to-stack-buffer#3781
semgrep-dev-pr-bot[bot] wants to merge 2 commits intodevelopfrom
semgrep-live-boL4Z

Conversation

@semgrep-dev-pr-bot
Copy link
Copy Markdown
Contributor

Wahoo! New published rules with dannytheway_personal.unbounded-copy-to-stack-buffer from @dannytheway.

See semgrep.dev/s/boL4Z for more details.

Thanks for your contribution! ❤️

void foo() {
char buf[64];
// ruleid: unbounded-copy-to-stack-buffer
gets(buf);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Semgrep identified an issue in your code:
The gets() function reads a line from stdin into the provided buffer
until either a terminating newline or EOF. This terminating newline or
EOF is replaced with a null byte '\0'. No check for buffer overruns are
performed so it is recommended to use fgets() instead. Do note
that some platforms will continue reading data after a '\0' is encountered.

Usage of fgets() is not recommended for reading binary based files or inputs,
instead the read or fread functions should be used.

For more information please see: https://linux.die.net/man/3/fgets

To resolve this comment:

🔧 No guidance has been designated for this issue. Fix according to your organization's approved methods.

💬 Ignore this finding

Reply with Semgrep commands to ignore this finding.

  • /fp <comment> for false positive
  • /ar <comment> for acceptable risk
  • /other <comment> for all other reasons

Alternatively, triage in Semgrep AppSec Platform to ignore the finding created by _getts-1.

You can view more details about this finding in the Semgrep AppSec Platform.

void test_001() {
char buf[BUFFER_SIZE];
// ruleid: unbounded-copy-to-stack-buffer
if (gets(buf) == NULL) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Semgrep identified an issue in your code:
The gets() function reads a line from stdin into the provided buffer
until either a terminating newline or EOF. This terminating newline or
EOF is replaced with a null byte '\0'. No check for buffer overruns are
performed so it is recommended to use fgets() instead. Do note
that some platforms will continue reading data after a '\0' is encountered.

Usage of fgets() is not recommended for reading binary based files or inputs,
instead the read or fread functions should be used.

For more information please see: https://linux.die.net/man/3/fgets

To resolve this comment:

🔧 No guidance has been designated for this issue. Fix according to your organization's approved methods.

💬 Ignore this finding

Reply with Semgrep commands to ignore this finding.

  • /fp <comment> for false positive
  • /ar <comment> for acceptable risk
  • /other <comment> for all other reasons

Alternatively, triage in Semgrep AppSec Platform to ignore the finding created by _getts-1.

You can view more details about this finding in the Semgrep AppSec Platform.

@semgrep-zcs-prod-semgrep
Copy link
Copy Markdown

Semgrep found 17 unbounded-copy-to-stack-buffer findings:

The function sscanf does not impose any size limitation to what it writes to buf. That may lead to a stack buffer overflow if there is no validation on the size of the input.

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