Repository navigation
CQ: Fix CodeQL issues "Incorrect return-value check for a 'scanf'-like function" - #7673
Merged
Merged
Conversation
… check for a 'scanf'-like function Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
… check for a 'scanf'-like function Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
…tion" for null value
echoix
force-pushed
the
alert-autofix-202
branch
from
July 12, 2026 11:26
f496ac5 to
7152c9f
Compare
…ction" for disturbed_land default value Adresses https://github.com/OSGeo/grass/security/code-scanning/532
Member
Author
|
@petrasovaa I added the fix to of https://github.com/OSGeo/grass/security/code-scanning/532, does it make sense in this situation for you too? |
Member
Author
|
There should be no other CodeQL alerts of this type after merging this |
wenzeslaus
approved these changes
Jul 13, 2026
wenzeslaus
left a comment
Member
There was a problem hiding this comment.
I think the intention is: "on failure to read use fallback to the hardcoded value", so yes, any failure should trigger that, and so the change is correct.
My understanding is that there is no change in behavior because with one formatting specifies, the function will still only read first one item even if there is multiple valid values. Perhaps obvious, but it crossed my mind, so I examined also that angle.
echoix
added a commit
to wenzeslaus/grass
that referenced
this pull request
Jul 14, 2026
…e function" (OSGeo#7673) Follow-up from OSGeo#7660 This PR applies the same logic as the other PR, where how sscanf can also return EOF "if input failure occurs before the first receiving argument was assigned". (See https://en.cppreference.com/c/io/fscanf). Here, the little touch that is different for `raster/r.out.vtk/writeascii.c` and `raster3d/r3.out.vtk/writeVTKData.c`, is that I assume that if there's the `EOF` case, or any invalid case for the `null_value`, we would still want the null value to be 0. I think that's the design intention behind the code. This was assisted by AI (Copilot-generated fix suggestions for code scanning alerts), but we can reason through it and I applied some myself in order to batch them in one single PR. This should fix: - https://github.com/OSGeo/grass/security/code-scanning/525 - https://github.com/OSGeo/grass/security/code-scanning/526 - https://github.com/OSGeo/grass/security/code-scanning/527 - https://github.com/OSGeo/grass/security/code-scanning/528 - https://github.com/OSGeo/grass/security/code-scanning/531 - https://github.com/OSGeo/grass/security/code-scanning/532 - https://github.com/OSGeo/grass/security/code-scanning/533 * Potential fix for code scanning alert no. 525: Incorrect return-value check for a 'scanf'-like function Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> * Potential fix for code scanning alert no. 528: Incorrect return-value check for a 'scanf'-like function Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> * Update writeascii.c * r3.out.vtk: Fix "Incorrect return-value check for a 'scanf'-like function" for null value * r.watershed: Fix "Incorrect return-value check for a 'scanf'-like function" for disturbed_land default value Adresses https://github.com/OSGeo/grass/security/code-scanning/532 --------- Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
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.
Follow-up from #7660
This PR applies the same logic as the other PR, where how sscanf can also return EOF "if input failure occurs before the first receiving argument was assigned". (See https://en.cppreference.com/c/io/fscanf).
Here, the little touch that is different for
raster/r.out.vtk/writeascii.candraster3d/r3.out.vtk/writeVTKData.c, is that I assume that if there's theEOFcase, or any invalid case for thenull_value, we would still want the null value to be 0. I think that's the design intention behind the code.This was assisted by AI (Copilot-generated fix suggestions for code scanning alerts), but we can reason through it and I applied some myself in order to batch them in one single PR.
This should fix: