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

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