Skip to content

Fix Coverity NullReferenceException Issues w/ Remotes #1083

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

Closed
wants to merge 2 commits into from
Closed

Fix Coverity NullReferenceException Issues w/ Remotes #1083

wants to merge 2 commits into from

Conversation

whoisj
Copy link

@whoisj whoisj commented Jun 8, 2015

The issue here is that the method asserts that both parameters are null or neither are, then proceeds to behave like only one is. This results in a NRE too deep into the stack to easily debug/resolve the issue. Moving the error upstream makes it easier to identify the problem.

Question: should we just throw at the call-site if both arguments (remote and url) are null?

Included some beautification as a separate commit.


if (url != null)
{
remoteHandle = Proxy.git_remote_create_anonymous(repoHandle, url);
}
else
else if (remote != null)
Copy link
Member

Choose a reason for hiding this comment

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

We're actually asserting to protect against this. And the call to Debug.Assert is "seen" by Coverity, however it looks like the tool doesn't properly take it into account in the code flow analysis.

Copy link
Member

Choose a reason for hiding this comment

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

yeah - the ^ operator is the exclusive-or operator.

Copy link
Author

Choose a reason for hiding this comment

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

Coverity is correct. We in fact do assert but only in debug mode. We then have code flow for when both are null which should be an impossibility. We even dereference a null value in the malformed code flow that we assert, but do not check, will not happen.

Copy link
Member

Choose a reason for hiding this comment

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

this is correct. However, this is not a public method so we do control all callers of this method. Either way, I agree that this is a bit fragile. What would you think about throwing an exception in the case where we get unexpected input? Or, performing the refactoring suggested in #1084. As you mentioned, I think everyone agrees on the ultimate structure for this code (two methods).

@whoisj
Copy link
Author

whoisj commented Jun 9, 2015

Superceded by #1087

@whoisj whoisj closed this Jun 9, 2015
@whoisj whoisj deleted the fix-coverity-nre-issues-w-remote branch June 10, 2015 16:19
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