From: tb Date: Mon, 6 Nov 2023 14:50:12 +0000 (+0000) Subject: Fix a for loop bug introduced in the concurrency refactor X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=9e8c2326bee7b7ae38b9cf63beb74ca03df9dc72;p=openbsd Fix a for loop bug introduced in the concurrency refactor Due to Go's idiosyncratic semantics of for loops, tests would only run some of the test groups in the JSON file because by the time the closure is called, the array index could be changed. For example, on fast 8 core machines, the CMAC tests would run the last test group with key size 320 eight times rather than each of the eight test groups once. Make a copy of the pointer before passing it to the closure to avoid this issue. Simpler version of my initial fix from jsing --- diff --git a/regress/lib/libcrypto/wycheproof/wycheproof.go b/regress/lib/libcrypto/wycheproof/wycheproof.go index fa031921619..7994e13879e 100644 --- a/regress/lib/libcrypto/wycheproof/wycheproof.go +++ b/regress/lib/libcrypto/wycheproof/wycheproof.go @@ -1,4 +1,4 @@ -/* $OpenBSD: wycheproof.go,v 1.146 2023/11/06 14:43:02 tb Exp $ */ +/* $OpenBSD: wycheproof.go,v 1.147 2023/11/06 14:50:12 tb Exp $ */ /* * Copyright (c) 2018 Joel Sing * Copyright (c) 2018,2019,2022 Theo Buehler @@ -2771,7 +2771,8 @@ func runTestVectors(path string, variant testVariant) bool { wtv.Algorithm, wtv.NumberOfTests, filepath.Base(path)) success := true - for i := range wtv.TestGroups { + for _, tg := range wtv.TestGroups { + testGroupJSON := tg testc.runTest(func() bool { var wtg interface{} switch wtv.Algorithm { @@ -2826,7 +2827,7 @@ func runTestVectors(path string, variant testVariant) bool { return false } - if err := json.Unmarshal(wtv.TestGroups[i], wtg); err != nil { + if err := json.Unmarshal(testGroupJSON, wtg); err != nil { log.Fatalf("Failed to unmarshal test groups JSON: %v", err) } switch wtv.Algorithm {