grass
grass copied to clipboard
g.region/r.to.rast3elev: fixed scanf error to recognize EOF as a possible return value
scanf can return EOF as a return value, which can be a security issue if not accounted for.
@HuidaeCho with this PR now limited to only three changes with checks like == 1, is this PR ready to go?
Not only does the parser either return NULL or a non-empty string, the string is also guaranteed to contain a valid integer as it already been tested with https://github.com/OSGeo/grass/blob/8a3c6b7c7627036bf52681cdcb9c9833c398d6ac/lib/gis/parser.c#L1399
There is no way a compiler/static analyser could know this.
I see two possible "solutions" to this:
- Change to early exit strategy: eg.
if (sscanf(value, "%i", &pix) != 1) die(parm.grow); - Silence the warning with void: eg.
if ((void)sscanf(value, "%i", &pix)) {
if (sscanf(value, "%i", &pix) == 1) { without response if the if condition is false, will only lead to new problems.