Эх сурвалжийг харах

Make sure crypt module does not panic with unknown password format.

Bozhin Zafirov 5 өдөр өмнө
parent
commit
0a9cdb726e
1 өөрчлөгдсөн 4 нэмэгдсэн , 0 устгасан
  1. 4 0
      crypt.go

+ 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)