Skip to content

Commit

Permalink
Fix null pointer deref in diff if no Upstream (#3549)
Browse files Browse the repository at this point in the history
* Fix null pointer deref in diff if no Upstream

Running `kpt pkg diff` without an upstream set panics because we attempt
to dereference `kptFile.Upstream` without checking to see if it is nil.
This commit adds a check and returns early if necessary.

* Update internal/util/diff/diff.go

Co-authored-by: Natasha Sarkar <natashasarkar@google.com>

Co-authored-by: Natasha Sarkar <natashasarkar@google.com>
  • Loading branch information
Ralph7C2 and natasha41575 committed Sep 9, 2022
1 parent 0f54b2f commit c6adbb3
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/util/diff/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ func (c *Command) Run(ctx context.Context) error {
return errors.Errorf("package missing Kptfile at '%s': %v", c.Path, err)
}

// Return early if upstream is not set
if kptFile.Upstream == nil || kptFile.Upstream.Git == nil {
return errors.Errorf("package missing upstream in Kptfile at '%s'", c.Path)
}

// Create a staging directory to store all compared packages
stagingDirectory, err := os.MkdirTemp("", "kpt-")
if err != nil {
Expand Down

0 comments on commit c6adbb3

Please sign in to comment.