Skip to content

Potential fix for code scanning alert no. 239: Incorrect return-value check for a 'scanf'-like function - #663

Closed
echoix wants to merge 1 commit into
mainfrom
alert-autofix-239
Closed

echoix wants to merge 1 commit into
mainfrom
alert-autofix-239

Conversation

@echoix

@echoix echoix commented Jul 9, 2026

Copy link
Copy Markdown
Owner

Potential fix for https://github.com/echoix/grass/security/code-scanning/239

The correct fix is to validate sscanf return values against the exact expected number of matched items, not just truthiness.

In raster/r.to.rast3elev/main.c, update both numeric parsing checks:

  • Line around if (sscanf(param.upper->answer, "%lf", &db.upper))
  • Line around if (sscanf(param.lower->answer, "%lf", &db.lower))

Change each condition to == 1, since each call expects exactly one %lf conversion. This preserves existing behavior for valid input while correctly rejecting parse failures and any non-success return values (including EOF).

No new methods, imports, or dependencies are needed.

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

… check for a 'scanf'-like function

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@echoix echoix closed this Jul 13, 2026
@echoix
echoix deleted the alert-autofix-239 branch September 12, 2026 19:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant