Răsfoiți Sursa

Add stronger nonce/confidence parsing (#865)

* Add negative guards for nonce and confirmation number/level

* Fix copy pasta on nonce vs consistencyLevel

* Add more direct int parsing of args

* Remove redundant checks for upper/lower bounds on int parsing

Co-authored-by: claudijd <jclaudius@jumptrading.com>
Jonathan Claudius 3 ani în urmă
părinte
comite
6686d6aec8
1 a modificat fișierele cu 2 adăugiri și 10 ștergeri
  1. 2 10
      clients/eth/main.go

+ 2 - 10
clients/eth/main.go

@@ -51,25 +51,17 @@ func init() {
 }
 
 func postMessage(cmd *cobra.Command, args []string) {
-	nonce, err := strconv.Atoi(args[0])
+	nonce, err := strconv.ParseUint(args[0], 10, 32)
 	if err != nil {
 		cmd.PrintErrln("Could not parse nonce", err)
 		os.Exit(1)
 	}
-	if nonce > math.MaxUint32 {
-		cmd.PrintErrln("Nonce must not exceed MaxUint32", err)
-		os.Exit(1)
-	}
 
-	consistencyLevel, err := strconv.Atoi(args[1])
+	consistencyLevel, err := strconv.ParseUint(args[1], 10, 8)
 	if err != nil {
 		cmd.PrintErrln("Could not parse confirmation number", err)
 		os.Exit(1)
 	}
-	if consistencyLevel > math.MaxUint8 {
-		cmd.PrintErrln("Confirmation number must not exceed 255", err)
-		os.Exit(1)
-	}
 
 	message := common.Hex2Bytes(args[2])