Fix integer overflow in device_list_update.go (#1717)

Fix #1511
On 32-bits systems, int(hash.Sum32()) can be negative.
This makes the computation of array indices using modulo invalid, crashing dendrite.
Signed-off-by: Loïck Bonniot <git@lesterpig.com>
This commit is contained in:
Loïck Bonniot 2021-01-18 13:43:15 +01:00 committed by GitHub
parent cf82e08096
commit 940577cd3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -245,7 +245,7 @@ func (u *DeviceListUpdater) notifyWorkers(userID string) {
}
hash := fnv.New32a()
_, _ = hash.Write([]byte(remoteServer))
index := int(hash.Sum32()) % len(u.workerChans)
index := int(int64(hash.Sum32()) % int64(len(u.workerChans)))
ch := u.assignChannel(userID)
u.workerChans[index] <- remoteServer