-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Coverity fixes round 7 #3677
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Coverity fixes round 7 #3677
Conversation
@@ -86,7 +86,8 @@ int git_config__cvar(int *out, git_config *config, git_cvar_cached cvar) | |||
struct map_data *data = &_cvar_maps[(int)cvar]; | |||
git_config_entry *entry; | |||
|
|||
git_config__lookup_entry(&entry, config, data->cvar_name, false); | |||
if ((error = git_config__lookup_entry(&entry, config, data->cvar_name, false)) < 0) | |||
return error; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This bypasses setting our output variable to the default value. We were doing the equivalent of detecting a not-found entry (or whatever error) by checking entry
against NULL
in the check below.
This indicates we don't have nearly enough testing here, since now we're not setting *out
anymore, but the tests still pass.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact it does not, see the commit message. git_config__lookup_entry
with no_errors == false
calls get_entry
with GET_NO_MISSING
. So we shouldn't get an error for missing entries.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what happens when you look at the diff on its own. Ok, let's leave it as-is.
We usually check entries returned by `git_sortedcache_entry` for NULL pointers. As we have a write lock in `packed_write`, though, it really should not happen that the function returns NULL. Assert that ref is not NULL to silence a Coverity warning.
When normalizing options we try to look up HEAD's OID. While this action may fail in malformed repositories we never check the return value of the function. Fix the issue by converting `normalize_options` to actually return an error and handle the error in `git_blame_file`.
Accessing the current values map is handled through the `refcounder_strmap_take` function, which first acquires a mutex before accessing its values. While this assures everybody is trying to access the values with the mutex only we do not check if the locking actually succeeds. Fix the issue by checking if acquiring the lock succeeds and returning `NULL` if we encounter an error. Adjust callers.
When writing to a file with locking not check if writing the locked file actually succeeds. Fix the issue by returning error code and message when writing fails.
Callers of `git_config__cvar` already handle the case where the function returns an error due to a failed configuration variable lookup, but we are actually swallowing errors when calling `git_config__lookup_entry` inside of the function. Fix this by returning early when `git_config__lookup_entry` returns an error. As we call `git_config__lookup_entry` with `no_errors == false` which leads us to call `get_entry` with `GET_NO_MISSING` we will not return early when the lookup fails due to a missing entry. Like this we are still able to set the default value of the cvar and exit successfully.
64036ba
to
13c371d
Compare
@pks-t That looks reasonable to me - is this just a one-time manual upload or is this something automated? |
@ethomson In theory there should be a So for now this would be a one-time manual upload and nothing automated. But right now I don't see anything that should be modeled anyway, so I don't expect it to change frequently. |
Mostly fixes involving ignored return codes. Down to a defect density of 0.25 and 29 defects outstanding in my fork.
While we're at it: I've got a custom user model that fixes how Coverity models vectors (see user_model.c). It fixes some issues but requires us to manually upload the file into Coverity. Do we want this added?