Protecting the read index is not out of bounds (#17226)

This commit is contained in:
jiuker 2023-05-18 03:09:41 +08:00 committed by GitHub
parent 85912985b6
commit f037c9b286
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -221,16 +221,15 @@ func (s *erasureSets) connectDisks() {
if disk.IsLocal() && disk.Healing() != nil { if disk.IsLocal() && disk.Healing() != nil {
globalBackgroundHealState.pushHealLocalDisks(disk.Endpoint()) globalBackgroundHealState.pushHealLocalDisks(disk.Endpoint())
} }
s.erasureDisksMu.RLock() s.erasureDisksMu.Lock()
setIndex, diskIndex, err := findDiskIndex(s.format, format) setIndex, diskIndex, err := findDiskIndex(s.format, format)
s.erasureDisksMu.RUnlock()
if err != nil { if err != nil {
printEndpointError(endpoint, err, false) printEndpointError(endpoint, err, false)
disk.Close() disk.Close()
s.erasureDisksMu.Unlock()
return return
} }
s.erasureDisksMu.Lock()
if currentDisk := s.erasureDisks[setIndex][diskIndex]; currentDisk != nil { if currentDisk := s.erasureDisks[setIndex][diskIndex]; currentDisk != nil {
if !reflect.DeepEqual(currentDisk.Endpoint(), disk.Endpoint()) { if !reflect.DeepEqual(currentDisk.Endpoint(), disk.Endpoint()) {
err = fmt.Errorf("Detected unexpected drive ordering refusing to use the drive: expecting %s, found %s, refusing to use the drive", err = fmt.Errorf("Detected unexpected drive ordering refusing to use the drive: expecting %s, found %s, refusing to use the drive",