summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry/strace
diff options
context:
space:
mode:
authorAndrei Vagin <avagin@google.com>2019-12-03 13:46:09 -0800
committergVisor bot <gvisor-bot@google.com>2019-12-03 13:49:38 -0800
commit43643752f05a0b25259b116558ccd870a539cc05 (patch)
tree02d983fe588bdad49c8fdbb85eb401a8f504cd45 /pkg/sentry/strace
parent154dcdec072ddad9e1c96b56e023d7f77fecf2ad (diff)
strace: don't create a slice with a negative value
PiperOrigin-RevId: 283613824
Diffstat (limited to 'pkg/sentry/strace')
-rw-r--r--pkg/sentry/strace/socket.go9
1 files changed, 9 insertions, 0 deletions
diff --git a/pkg/sentry/strace/socket.go b/pkg/sentry/strace/socket.go
index 94334f6d2..51f2efb39 100644
--- a/pkg/sentry/strace/socket.go
+++ b/pkg/sentry/strace/socket.go
@@ -208,6 +208,15 @@ func cmsghdr(t *kernel.Task, addr usermem.Addr, length uint64, maxBytes uint64)
i += linux.SizeOfControlMessageHeader
width := t.Arch().Width()
length := int(h.Length) - linux.SizeOfControlMessageHeader
+ if length < 0 {
+ strs = append(strs, fmt.Sprintf(
+ "{level=%s, type=%s, length=%d, content too short}",
+ level,
+ typ,
+ h.Length,
+ ))
+ break
+ }
if skipData {
strs = append(strs, fmt.Sprintf("{level=%s, type=%s, length=%d}", level, typ, h.Length))