go-ldap / ldap

Basic LDAP v3 functionality for the GO programming language.
Other
2.19k stars 352 forks source link

Fix DATA RACE as a result of changing ber's module global variable for fuzz tests #473

Closed t2y closed 7 months ago

t2y commented 7 months ago

I investigated why DATA RACE occurred.

WARNING: DATA RACE
Write at 0x000000c3c628 by goroutine 38:
  github.com/go-ldap/ldap.FuzzParseDN()
      /home/runner/work/ldap/ldap/fuzz_test.go:14 +0x32
  testing.fRunner()
      /opt/hostedtoolcache/go/1.18.10/x64/src/testing/fuzz.go:700 +0x168
  testing.runFuzzTests.func1()
      /opt/hostedtoolcache/go/1.18.10/x64/src/testing/fuzz.go:5[20](https://github.com/go-ldap/ldap/actions/runs/6781841980/job/18432888679#step:5:21) +0x47

Fuzz tests also run as unit tests, so the module global variable shouldn't change in a test function.

ber.MaxPacketLengthBytes = 65536

I fix this conflict by adding TestMain(), which handles a setup process before all tests. Now, all tests run with ber.MaxPacketLengthBytes limitation. Does it make sense?

See also #472.

References

johnweldon commented 7 months ago

Thank you @t2y We do want this in the v3 folder eventually, but for now this will get you past the CI errors.