Skip to content

Commit

Permalink
Merge pull request warewulf#939 from mslacken/DontPanic
Browse files Browse the repository at this point in the history
don't panic on malformed passwd
  • Loading branch information
anderbubble authored Dec 9, 2023
2 parents 87b55a2 + 7de3c1c commit 98b36a5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Don't show an error if image files for containers can't be found. #933
- Make configured paths available in overlays as `.Path` #960
- Support importing containers with symlinked `/bin/sh` #797
- Don't panic on malformed passwd #527

## [4.4.0] 2023-01-18

Expand Down
5 changes: 4 additions & 1 deletion internal/pkg/container/syncuids.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,10 @@ func (db syncDB) read(fileName string, fromContainer bool) error {
for fileScanner.Scan() {
line := fileScanner.Text()
fields := strings.Split(line, ":")

if len(fields) != 7 {
wwlog.Debug("malformed line in passwd: %s", line)
continue
}
name := fields[0]
if name == "" {
continue
Expand Down
10 changes: 10 additions & 0 deletions internal/pkg/container/syncuids_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,13 @@ func Test_differ(t *testing.T) {
assert.False(t, entry.match())
assert.True(t, entry.differ())
}

func Test_malformed_passwd(t *testing.T) {
hostInput := `"testuser1:x:1001:1001::/home/testuser:/bin/bash"
asdf`
hostFileName := writeTempFile(t, hostInput)
defer os.Remove(hostFileName)
db := make(syncDB)
err := db.readFromHost(hostFileName)
assert.NoError(t, err)
}

0 comments on commit 98b36a5

Please sign in to comment.