Skip to content

Commit

Permalink
mr_edit: Fix panic with --assign option
Browse files Browse the repository at this point in the history
lab panics if the 'mr edit' assign option is used with an invalid
username.

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x482346]

goroutine 1 [running]:
cmd.getUpdateAssignees
	/home/prarit/git-kernel/github/lab/cmd/edit_common.go:38
cmd.func38
	/home/prarit/git-kernel/github/lab/cmd/mr_edit.go:122
github.x2ecom..z2fspf13..z2fcobra.Command.execute
	/home/prarit/go/pkg/mod/github.com/spf13/[email protected]/command.go:854
github.x2ecom..z2fspf13..z2fcobra.Command.ExecuteC
	/home/prarit/go/pkg/mod/github.com/spf13/[email protected]/command.go:958
github.x2ecom..z2fspf13..z2fcobra.Command.Execute
	/home/prarit/go/pkg/mod/github.com/spf13/[email protected]/command.go:895
github.x2ecom..z2fzaquestion..z2flab..z2fcmd.Execute
	/home/prarit/git-kernel/github/lab/cmd/root.go:244
main.main
	/home/prarit/git-kernel/github/lab/main.go:28

This occurs because the code does not check for a valid return from the
getUserID() function.

Check that the specified --assign users are valid GitLab usernames.

Signed-off-by: Prarit Bhargava <[email protected]>
  • Loading branch information
prarit committed Mar 24, 2021
1 parent 7b53f9a commit 6cfaf6c
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cmd/edit_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"bufio"
"fmt"
"os"
"strings"

Expand Down Expand Up @@ -35,6 +36,9 @@ func getUpdateUsers(currentUsers []string, users []string, remove []string) ([]i
} else {
userIDs = make([]int, len(users))
for i, a := range users {
if getUserID(a) == nil {
return nil, false, fmt.Errorf("Error: %s is not a valid username\n", a)
}
userIDs[i] = *getUserID(a)
}
}
Expand Down

0 comments on commit 6cfaf6c

Please sign in to comment.