From: Simon Ruderich <simon@ruderich.org>
Date: Sat, 8 Jun 2019 13:49:55 +0000 (+0200)
Subject: nsscash: improve index sanity check
X-Git-Tag: 0.1~86
X-Git-Url: https://ruderich.org/simon/gitweb/?a=commitdiff_plain;h=d7eb5ee1a910303f38904e604aea9cf0b1372d7b;p=nsscash%2Fnsscash.git

nsscash: improve index sanity check

This ensures that the index has the proper size and is not missing any
entries.
---

diff --git a/group.go b/group.go
index 02502f6..7cc0841 100644
--- a/group.go
+++ b/group.go
@@ -209,7 +209,8 @@ func SerializeGroups(w io.Writer, grs []Group) error {
 	}
 
 	// Sanity check
-	if indexOrig.Len() != indexId.Len() ||
+	if len(grs)*8 != indexOrig.Len() ||
+		indexOrig.Len() != indexId.Len() ||
 		indexId.Len() != indexName.Len() {
 		return fmt.Errorf("indexes have inconsistent length")
 	}
diff --git a/passwd.go b/passwd.go
index c07e9c7..1b4939c 100644
--- a/passwd.go
+++ b/passwd.go
@@ -191,7 +191,8 @@ func SerializePasswds(w io.Writer, pws []Passwd) error {
 	}
 
 	// Sanity check
-	if indexOrig.Len() != indexId.Len() ||
+	if len(pws)*8 != indexOrig.Len() ||
+		indexOrig.Len() != indexId.Len() ||
 		indexId.Len() != indexName.Len() {
 		return fmt.Errorf("indexes have inconsistent length")
 	}