X-Git-Url: https://ruderich.org/simon/gitweb/?p=nsscash%2Fnsscash.git;a=blobdiff_plain;f=passwd.go;h=c9f4409c2bbb013f99631d251389f2e8d2e85de9;hp=54da63b3f30252f65e5c1717318b683686a037c1;hb=a3031f694a0d58d23d383346ee848a6c78a1e4b9;hpb=7adc7f83eddd37aa372aa10159128b6d16c4320a diff --git a/passwd.go b/passwd.go index 54da63b..c9f4409 100644 --- a/passwd.go +++ b/passwd.go @@ -23,6 +23,7 @@ import ( "encoding/binary" "fmt" "io" + "math" "sort" "strconv" "strings" @@ -103,6 +104,11 @@ func SerializePasswd(p Passwd) ([]byte, error) { offShell := uint16(data.Len()) data.Write([]byte(p.Shell)) data.WriteByte(0) + // Ensure the offsets can fit the length of this entry + if data.Len() > math.MaxUint16 { + return nil, fmt.Errorf("passwd too large to serialize: %v, %v", + data.Len(), p) + } size := uint16(data.Len()) var res bytes.Buffer // serialized result