Fix unsigned to signed integer conversion in syserr.getHostTranslation().

unix.Errno is of type `uintptr`, which is an unsigned integer. It was being
casted to `int`, which is a signed integer of the same size. This cast could
overflow due to unsigned -> signed.

Reported-by: syzbot+08e5bf6f25d7db4316b9@syzkaller.appspotmail.com
PiperOrigin-RevId: 680668525
This commit is contained in:
Ayush Ranjan
2024-09-30 12:11:53 -07:00
committed by gVisor bot
parent 3971ecbc6c
commit 9d41ac1ff0
2 changed files with 2 additions and 2 deletions
+1 -1
View File
@@ -28,7 +28,7 @@ const maxErrno = 107
var darwinHostTranslations [maxErrno]*Error
func getHostTranslation(err unix.Errno) *Error {
if int(err) >= len(darwinHostTranslations) {
if uint64(err) >= uint64(len(darwinHostTranslations)) {
return nil
}
return darwinHostTranslations[err]
+1 -1
View File
@@ -29,7 +29,7 @@ const maxErrno = 134
var linuxHostTranslations [maxErrno]*Error
func getHostTranslation(err unix.Errno) *Error {
if int(err) >= len(linuxHostTranslations) {
if uint64(err) >= uint64(len(linuxHostTranslations)) {
return nil
}
return linuxHostTranslations[err]