diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c6287b3..5636be7a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/internal/pkg/container/syncuids.go b/internal/pkg/container/syncuids.go index 529b2e86..1222c6b6 100644 --- a/internal/pkg/container/syncuids.go +++ b/internal/pkg/container/syncuids.go @@ -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 diff --git a/internal/pkg/container/syncuids_test.go b/internal/pkg/container/syncuids_test.go index 70951b92..abaad68a 100644 --- a/internal/pkg/container/syncuids_test.go +++ b/internal/pkg/container/syncuids_test.go @@ -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) +}