Merge pull request #939 from mslacken/DontPanic

don't panic on malformed passwd
This commit is contained in:
Jonathon Anderson
2023-12-09 02:09:05 -07:00
committed by GitHub
3 changed files with 15 additions and 1 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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)
}