]> ruderich.org/simon Gitweb - nsscash/nsscash.git/blobdiff - group.go
nsscash: replace %s with %v in format string for File.Type
[nsscash/nsscash.git] / group.go
index 126ebb0dc349e0127c4ff14f3b61f48cb99cc737..b96f6b14aa4c779cc59c1ebc4498c96a5fefcdb2 100644 (file)
--- a/group.go
+++ b/group.go
@@ -26,6 +26,7 @@ import (
        "sort"
        "strconv"
        "strings"
+       "math"
 
        "github.com/pkg/errors"
 )
@@ -67,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
@@ -130,6 +136,11 @@ func SerializeGroup(g Group) ([]byte, error) {
        }
        // And the group members concatenated as above
        data.Write(mems.Bytes())
+       // Ensure the offsets can fit the length of this entry
+       if data.Len() > math.MaxUint16 {
+               return nil, fmt.Errorf("group too large to serialize: %v, %v",
+                       data.Len(), g)
+       }
        size := uint16(data.Len())
 
        var res bytes.Buffer // serialized result