forked from git/git
-
Notifications
You must be signed in to change notification settings - Fork 142
Some defensive programming #1890
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
Open
dscho
wants to merge
14
commits into
gitgitgadget:master
Choose a base branch
from
dscho:defensive-programming
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
604e67e
revision: defensive programming
dscho 35c4870
get_parent(): defensive programming
dscho 9cafbd3
fetch-pack: defensive programming
dscho dcc04af
unparse_commit(): defensive programming
dscho 721402d
verify_commit_graph(): defensive programming
dscho 130251b
stash: defensive programming
dscho 81e873e
stash: defensive programming
dscho 8d1efe0
push: defensive programming
dscho d839766
fetch: defensive programming
dscho 10393c2
describe: defensive programming
dscho dec21f8
inherit_tracking(): defensive programming
dscho 223a005
submodule: check return value of `submodule_from_path()`
dscho 137f6c4
test-tool repository: check return value of `lookup_commit()`
dscho 17e9e9a
shallow: handle missing shallow commits gracefully
dscho File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1106,7 +1106,7 @@ static enum get_oid_result get_parent(struct repository *r, | |
if (ret) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Jeff King wrote (reply to this): On Thu, May 15, 2025 at 12:45:27PM +0000, Johannes Schindelin via GitGitGadget wrote:
> CodeQL points out that `lookup_commit_reference()` can return NULL
> values.
> [...]
> commit = lookup_commit_reference(r, &oid);
> - if (repo_parse_commit(r, commit))
> + if (!commit || repo_parse_commit(r, commit))
> return MISSING_OBJECT;
Sure, but repo_parse_commit() can also handle NULL values. It returns
"-1" in that case. I think CodeQL is not smart enough to know that.
-Peff |
||
return ret; | ||
commit = lookup_commit_reference(r, &oid); | ||
if (repo_parse_commit(r, commit)) | ||
if (!commit || repo_parse_commit(r, commit)) | ||
return MISSING_OBJECT; | ||
if (!idx) { | ||
oidcpy(result, &commit->object.oid); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3359,6 +3359,9 @@ static int leave_one_treesame_to_parent(struct rev_info *revs, struct commit *co | |
struct commit_list *p; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Junio C Hamano wrote (reply to this): "Johannes Schindelin via GitGitGadget" <[email protected]>
writes:
> From: Johannes Schindelin <[email protected]>
>
> On the off chance that `lookup_decoration()` cannot find anything, let
> `leave_one_treesame_to_parent()` return gracefully instead of crashing.
But wouldn't it be a BUG("") worthy event for the treesame
decoration not to exist for the commit object in question at this
point of the code? Is it really defensive to silently pretend that
nothing bad happened and to move forward?
> Pointed out by CodeQL.
>
> Signed-off-by: Johannes Schindelin <[email protected]>
> ---
> revision.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/revision.c b/revision.c
> index c4390f0938cb..59eae4eb8ba8 100644
> --- a/revision.c
> +++ b/revision.c
> @@ -3359,6 +3359,9 @@ static int leave_one_treesame_to_parent(struct rev_info *revs, struct commit *co
> struct commit_list *p;
> unsigned n;
>
> + if (!ts)
> + return 0;
> +
> for (p = commit->parents, n = 0; p; p = p->next, n++) {
> if (ts->treesame[n]) {
> if (p->item->object.flags & TMP_MARK) { |
||
unsigned n; | ||
|
||
if (!ts) | ||
return 0; | ||
|
||
for (p = commit->parents, n = 0; p; p = p->next, n++) { | ||
if (ts->treesame[n]) { | ||
if (p->item->object.flags & TMP_MARK) { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
On the Git mailing list, Junio C Hamano wrote (reply to this):