From 9d41ac1ff0b2af780963f17e24b1d0b678c004dc Mon Sep 17 00:00:00 2001 From: Ayush Ranjan Date: Mon, 30 Sep 2024 12:06:56 -0700 Subject: [PATCH] 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 --- pkg/syserr/host_darwin.go | 2 +- pkg/syserr/host_linux.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/syserr/host_darwin.go b/pkg/syserr/host_darwin.go index 3e8783414..67fa71f95 100644 --- a/pkg/syserr/host_darwin.go +++ b/pkg/syserr/host_darwin.go @@ -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] diff --git a/pkg/syserr/host_linux.go b/pkg/syserr/host_linux.go index 8acd8609f..dc9a34746 100644 --- a/pkg/syserr/host_linux.go +++ b/pkg/syserr/host_linux.go @@ -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]