Trailing/empty entry in --groups list produces a confusing error message #4

Closed
opened 2026-07-25 11:30:39 +00:00 by AnmiTaliDev · 0 comments
AnmiTaliDev commented 2026-07-25 11:30:39 +00:00 (Migrated from github.com)

Description

LookupGroupsWith in src/user/user.go (lines 49-63) splits the --groups value on commas without filtering out empty entries:

func LookupGroupsWith(groupPath, groupList string) ([]int, error) {
	var gids []int
	for _, grp := range strings.Split(groupList, ",") {
		if g, err := strconv.Atoi(grp); err == nil {
			gids = append(gids, g)
		} else {
			g, err := findGIDByNameWith(groupPath, grp)
			if err != nil {
				return nil, fmt.Errorf("group %q not found", grp)
			}
			gids = append(gids, g)
		}
	}
	return gids, nil
}

If the list has a trailing (or leading, or doubled) comma, e.g. --groups=1000,, strings.Split produces ["1000", ""]. The empty string is then looked up as a group name and fails, producing the misleading error group "" not found instead of a message that points at the actual problem (an empty/malformed entry in the list).

Steps to reproduce

./warproot --userspec=1000 --groups=1000, /path/to/root

Expected behavior

Either skip empty entries produced by splitting, or return a clear error such as invalid --groups value: empty group name in list %q, so the user understands the list itself is malformed rather than thinking a group literally named "" doesn't exist.

### Description `LookupGroupsWith` in `src/user/user.go` (lines 49-63) splits the `--groups` value on commas without filtering out empty entries: ```go func LookupGroupsWith(groupPath, groupList string) ([]int, error) { var gids []int for _, grp := range strings.Split(groupList, ",") { if g, err := strconv.Atoi(grp); err == nil { gids = append(gids, g) } else { g, err := findGIDByNameWith(groupPath, grp) if err != nil { return nil, fmt.Errorf("group %q not found", grp) } gids = append(gids, g) } } return gids, nil } ``` If the list has a trailing (or leading, or doubled) comma, e.g. `--groups=1000,`, `strings.Split` produces `["1000", ""]`. The empty string is then looked up as a group name and fails, producing the misleading error `group "" not found` instead of a message that points at the actual problem (an empty/malformed entry in the list). ### Steps to reproduce ``` ./warproot --userspec=1000 --groups=1000, /path/to/root ``` ### Expected behavior Either skip empty entries produced by splitting, or return a clear error such as `invalid --groups value: empty group name in list %q`, so the user understands the list itself is malformed rather than thinking a group literally named `""` doesn't exist.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
utils/warproot#4
No description provided.