diff options
author | Ting-Yu Wang <anivia@google.com> | 2020-09-16 14:10:58 -0700 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2020-09-16 14:12:22 -0700 |
commit | 666397c5c82ee18a776491919312d19cfe6d4a07 (patch) | |
tree | 09ef6fd6f90d09ca7005cecfe4ff1e60ca6d09d4 /pkg/tcpip/link/rawfile/errors.go | |
parent | 0356c7ef32dfcc05b1f5e7f242a022883a9ba816 (diff) |
Gracefully translate unknown errno.
Neither POSIX.1 nor Linux defines an upperbound for errno.
PiperOrigin-RevId: 332085017
Diffstat (limited to 'pkg/tcpip/link/rawfile/errors.go')
-rw-r--r-- | pkg/tcpip/link/rawfile/errors.go | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/pkg/tcpip/link/rawfile/errors.go b/pkg/tcpip/link/rawfile/errors.go index a0a873c84..604868fd8 100644 --- a/pkg/tcpip/link/rawfile/errors.go +++ b/pkg/tcpip/link/rawfile/errors.go @@ -31,10 +31,12 @@ var translations [maxErrno]*tcpip.Error // *tcpip.Error. // // Valid, but unrecognized errnos will be translated to -// tcpip.ErrInvalidEndpointState (EINVAL). Panics on invalid errnos. +// tcpip.ErrInvalidEndpointState (EINVAL). func TranslateErrno(e syscall.Errno) *tcpip.Error { - if err := translations[e]; err != nil { - return err + if e > 0 && e < syscall.Errno(len(translations)) { + if err := translations[e]; err != nil { + return err + } } return tcpip.ErrInvalidEndpointState } |