2 Revize 8e3d5b88aa ... ed0316d615

Autor SHA1 Zpráva Datum
  Bozhin Zafirov ed0316d615 Add go.mod file to repository. před 1 měsícem
  Bozhin Zafirov 0a9cdb726e Make sure crypt module does not panic with unknown password format. před 1 měsícem
2 změnil soubory, kde provedl 7 přidání a 0 odebrání
  1. 4 0
      crypt.go
  2. 3 0
      go.mod

+ 4 - 0
crypt.go

@@ -17,6 +17,7 @@ import "C"
 
 // EPasswordIncorrect is a password verification failure error
 var EPasswordIncorrect = errors.New("passwords do not match")
+var EBadPasswordFormat = errors.New("bad password format")
 
 // Crypt wraps C library crypt_r
 func Crypt(Password, Salt string) (*string, error) {
@@ -54,6 +55,9 @@ func CompareHashAndPassword(Hash, Password string) error {
 	}
 	// Split salt from password
 	HashItems := strings.SplitN(Hash, "$", 4)
+	if len(HashItems) < 3 {
+		return EBadPasswordFormat
+	}
 	Salt := "$" + HashItems[1] + "$" + HashItems[2] + "$"
 
 	hash, err := Crypt(Password, Salt)

+ 3 - 0
go.mod

@@ -0,0 +1,3 @@
+module crypt
+
+go 1.24.4