Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Merged
merged 6 commits into from
Mar 14, 2016
Merged

Conversation

pks-t
Copy link
Member

@pks-t pks-t commented Mar 11, 2016

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?

@@ -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;
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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.

pks-t added 6 commits March 11, 2016 14:20
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.
@pks-t pks-t force-pushed the pks/coverity-fixes-round7 branch from 64036ba to 13c371d Compare March 11, 2016 13:20
carlosmn added a commit that referenced this pull request Mar 14, 2016
@carlosmn carlosmn merged commit 77394a2 into libgit2:master Mar 14, 2016
@pks-t
Copy link
Member Author

pks-t commented Mar 17, 2016

@carlosmn @ethomson @vmg
Any comment about the usermodel C file that I've proposed in this PR's description?

@ethomson
Copy link
Member

@pks-t That looks reasonable to me - is this just a one-time manual upload or is this something automated?

@pks-t
Copy link
Member Author

pks-t commented Mar 17, 2016

@ethomson In theory there should be a --user-model-file switch for coverity-analyze which you feed a compiled user model which might be obtained by another Coverity tool. But we actually aren't using coverity-analyze and documentation is certainly lacking.

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.

@pks-t pks-t deleted the pks/coverity-fixes-round7 branch June 21, 2016 05:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants