Don't panic on malformed passwd

Fixes #527

Signed-off-by: Christian Goll <cgoll@suse.com>
This commit is contained in:
Christian Goll
2023-10-05 11:56:44 +02:00
committed by Jonathon Anderson
parent 87b55a2a79
commit 7de3c1c5cd
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)
}