While reading a value from file for an integer, coverity check is giving following error
Calling function "fread" taints argument "readval"
//coverity note: Calling function "fread" taints argument "readval".
if(fread(&readval, sizeof(int), 1, fp) < 1) {
return;
} else {
//coverity note: Passing tainted variable "readval" to a tainted sink.
f1(&readval);
}
How to handle this error? What sanity checks I need to perform for 'readval' to ensure it is not corrupt.
So the problem is that you're using a tainted value ;)
In more detail, readval is set once by outside data and then potentially used as an argument to fseek. This argument could put you past the end of the file and cause your program to crash.
You need to put in some checks to make sure you aren't walking off the end of the file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With