]> ruderich.org/simon Gitweb - nsscash/nsscash.git/blobdiff - group.go
.github: update upstream actions to latest version
[nsscash/nsscash.git] / group.go
index 4ca213a0edfabc48fd7a95e4280509c4547c9d5c..018a0c32716c665c690c78903b6eccdb5435ac54 100644 (file)
--- a/group.go
+++ b/group.go
@@ -1,6 +1,6 @@
 // Parse /etc/group files and serialize them
 
-// Copyright (C) 2019  Simon Ruderich
+// Copyright (C) 2019-2021  Simon Ruderich
 //
 // This program is free software: you can redistribute it and/or modify
 // it under the terms of the GNU Affero General Public License as published by
@@ -23,10 +23,10 @@ import (
        "encoding/binary"
        "fmt"
        "io"
+       "math"
        "sort"
        "strconv"
        "strings"
-       "math"
 
        "github.com/pkg/errors"
 )
@@ -68,6 +68,11 @@ func ParseGroups(r io.Reader) ([]Group, error) {
                t, err := s.ReadString('\n')
                if err != nil {
                        if err == io.EOF {
+                               if t != "" {
+                                       return nil, fmt.Errorf(
+                                               "no newline in last line: %q",
+                                               t)
+                               }
                                break
                        }
                        return nil, err
@@ -189,7 +194,7 @@ func SerializeGroups(w io.Writer, grs []Group) error {
        tmp := make([]byte, 8)
 
        // Create index "sorted" in input order, used when iterating over all
-       // passwd entries (getgrent_r); keeping the original order makes
+       // group entries (getgrent_r); keeping the original order makes
        // debugging easier
        var indexOrig bytes.Buffer
        for _, g := range grs {