Skip to content

Fix auto-forking scenario in pr create - #726

Merged
mislav merged 1 commit into
masterfrom
pr-create-crash
Apr 1, 2020
Merged

Fix auto-forking scenario in pr create#726
mislav merged 1 commit into
masterfrom
pr-create-crash

Conversation

@mislav

@mislav mislav commented Apr 1, 2020

Copy link
Copy Markdown
Contributor

When an existing headRepo couldn't be detected, it's time to auto-fork one. Unfortunately, an obscure Go behavior made it seem like headRepo was a non-nil value, where in fact it did contain a nil pointer which would crash the process.

This avoids ever assigning nil pointers to var headRepo ghrepo.Interface. https://golang.org/doc/faq#nil_error

Fixes #722

When an existing `headRepo` couldn't be detected, it's time to auto-fork
one. Unfortunately, an obscure Go behavior made it seem like `headRepo`
was a non-nil value, where in fact it did contain a nil pointer which
would crash the process.

This avoids ever assigning nil pointers to `var headRepo ghrepo.Interface`.

@vilmibm vilmibm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

thanks for the quick fix!

Comment thread command/pr_create.go

// otherwise, determine the head repository with info obtained from the API
if headRepo == nil {
headRepo, _ = repoContext.HeadRepo()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This previously assigned (*api.Repository)(nil) (a null pointer) to a variable with an interface type, which would make the variable erroneously pass the head != nil check

@mislav
mislav merged commit e066e98 into master Apr 1, 2020
@mislav
mislav deleted the pr-create-crash branch April 1, 2020 17: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.

Panic when trying to create a PR to a repo without write access

2 participants