Skip to content

Commit

Permalink
Fix unsigned to signed integer conversion in syserr.getHostTranslatio…
Browse files Browse the repository at this point in the history
…n().

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
  • Loading branch information
ayushr2 authored and gvisor-bot committed Sep 30, 2024
1 parent 3971ecb commit 9d41ac1
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/syserr/host_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion pkg/syserr/host_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 9d41ac1

Please sign in to comment.