Skip to content

CQ: Fix CodeQL issues "Incorrect return-value check for a 'scanf'-like function" - #7673

Merged
echoix merged 6 commits into
OSGeo:mainfrom
echoix-org:alert-autofix-202
Jul 13, 2026
Merged

echoix merged 6 commits into
OSGeo:mainfrom
echoix-org:alert-autofix-202

Conversation

@echoix

@echoix echoix commented Jul 12, 2026 •

Copy link
Copy Markdown
Member

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.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:

@github-actions github-actions Bot added raster Related to raster data processing C Related code is in C module general raster3d labels Jul 12, 2026
echoix and others added 4 commits July 12, 2026 11:25
… 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>
@echoix
echoix force-pushed the alert-autofix-202 branch from f496ac5 to 7152c9f Compare July 12, 2026 11:26
@echoix

echoix commented Jul 13, 2026

Copy link
Copy Markdown
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?

@echoix
echoix requested review from petrasovaa and wenzeslaus July 13, 2026 07:23
@echoix

echoix commented Jul 13, 2026

Copy link
Copy Markdown
Member Author

There should be no other CodeQL alerts of this type after merging this

@wenzeslaus wenzeslaus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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
echoix merged commit 32785cd into OSGeo:main Jul 13, 2026
27 of 28 checks passed
@echoix
echoix deleted the alert-autofix-202 branch July 13, 2026 13:26
@github-actions github-actions Bot added this to the 8.6.0 milestone Jul 13, 2026
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C Related code is in C general module raster Related to raster data processing raster3d

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants