diff --git a/pkg/agehd/agehd_test.go b/pkg/agehd/agehd_test.go index 415ae14..531abbb 100644 --- a/pkg/agehd/agehd_test.go +++ b/pkg/agehd/agehd_test.go @@ -663,6 +663,10 @@ func TestConcurrentDerivation(t *testing.T) { for i := 0; i < testNumGoroutines; i++ { go func(goroutineID int) { for j := 0; j < testNumIterations; j++ { + if j < 0 || j > 1000000 { + errors <- fmt.Errorf("index out of safe range") + return + } identity, err := DeriveIdentity(mnemonic, uint32(j)) if err != nil { errors <- err @@ -706,7 +710,11 @@ func TestConcurrentDerivation(t *testing.T) { // Benchmark tests func BenchmarkDeriveIdentity(b *testing.B) { for i := 0; i < b.N; i++ { - _, err := DeriveIdentity(mnemonic, uint32(i%1000)) + index := i % 1000 + if index < 0 || index > 1000000 { + b.Fatalf("index out of safe range: %d", index) + } + _, err := DeriveIdentity(mnemonic, uint32(index)) if err != nil { b.Fatalf("derive identity: %v", err) } @@ -715,7 +723,11 @@ func BenchmarkDeriveIdentity(b *testing.B) { func BenchmarkDeriveIdentityFromXPRV(b *testing.B) { for i := 0; i < b.N; i++ { - _, err := DeriveIdentityFromXPRV(testXPRV, uint32(i%1000)) + index := i % 1000 + if index < 0 || index > 1000000 { + b.Fatalf("index out of safe range: %d", index) + } + _, err := DeriveIdentityFromXPRV(testXPRV, uint32(index)) if err != nil { b.Fatalf("derive identity from xprv: %v", err) } @@ -724,7 +736,11 @@ func BenchmarkDeriveIdentityFromXPRV(b *testing.B) { func BenchmarkDeriveEntropy(b *testing.B) { for i := 0; i < b.N; i++ { - _, err := DeriveEntropy(mnemonic, uint32(i%1000)) + index := i % 1000 + if index < 0 || index > 1000000 { + b.Fatalf("index out of safe range: %d", index) + } + _, err := DeriveEntropy(mnemonic, uint32(index)) if err != nil { b.Fatalf("derive entropy: %v", err) }