@@ -62,6 +62,7 @@ func parseLine(line []byte, v ...any) error {
6262
6363func parseParts (parts [][]byte , v ... any ) error {
6464 if len (parts ) == 0 {
65+ // TODO(thaJeztah); do we need an "ok" return so that we can skip these in loops?
6566 return nil
6667 }
6768
@@ -151,7 +152,9 @@ func ParsePasswdFilter(r io.Reader, filter func(User) bool) ([]User, error) {
151152 // adm:x:3:4:adm:/var/adm:/bin/false
152153 p := User {}
153154 if err := parseLine (line , & p .Name , & p .Pass , & p .Uid , & p .Gid , & p .Gecos , & p .Home , & p .Shell ); err != nil {
154- return nil , err
155+ // Skip malformed lines, and don't consider them.
156+ // return nil, fmt.Errorf("invalid line (%q): %w", string(line), err)
157+ continue
155158 }
156159
157160 if filter == nil || filter (p ) {
@@ -212,7 +215,9 @@ func ParseGroupFilter(r io.Reader, filter func(Group) bool) ([]Group, error) {
212215 // adm:x:4:root,adm,daemon
213216 p := Group {}
214217 if err := parseLine (line , & p .Name , & p .Pass , & p .Gid , & p .List ); err != nil {
215- return nil , err
218+ // Skip malformed lines, and don't consider them.
219+ // return nil, fmt.Errorf("invalid line (%q): %w", string(line), err)
220+ continue
216221 }
217222
218223 if filter == nil || filter (p ) {
@@ -559,6 +564,8 @@ func ParseSubIDFilter(r io.Reader, filter func(SubID) bool) ([]SubID, error) {
559564 // see: man 5 subuid
560565 p := SubID {}
561566 if err := parseLine (line , & p .Name , & p .SubID , & p .Count ); err != nil {
567+ // Skip malformed lines, and don't consider them.
568+ // return nil, fmt.Errorf("invalid line (%q): %w", string(line), err)
562569 return nil , err
563570 }
564571
@@ -609,7 +616,9 @@ func ParseIDMapFilter(r io.Reader, filter func(IDMap) bool) ([]IDMap, error) {
609616 // see: man 7 user_namespaces
610617 p := IDMap {}
611618 if err := parseParts (bytes .Fields (line ), & p .ID , & p .ParentID , & p .Count ); err != nil {
612- return nil , err
619+ // Skip malformed lines, and don't consider them.
620+ // return nil, fmt.Errorf("invalid line (%q): %w", string(line), err)
621+ continue
613622 }
614623
615624 if filter == nil || filter (p ) {
0 commit comments