X Tutup
Skip to content

Fix auto-forking scenario in pr create#726

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

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

Conversation

@mislav
Copy link
Contributor

@mislav mislav commented Apr 1, 2020

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`.
Copy link
Contributor

@vilmibm vilmibm left a comment

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!


// otherwise, determine the head repository with info obtained from the API
if headRepo == nil {
headRepo, _ = repoContext.HeadRepo()
Copy link
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

X Tutup