summaryrefslogtreecommitdiffhomepage
path: root/test/packetimpact
diff options
context:
space:
mode:
authorTamir Duberstein <tamird@google.com>2021-02-01 10:25:40 -0800
committergVisor bot <gvisor-bot@google.com>2021-02-01 10:29:39 -0800
commit726100f8eb88e8ea97ef5770b47a271276a8b741 (patch)
treea2c020b00a316b4467b83aa5667051a938615b71 /test/packetimpact
parentd930def27a433fc9f49ba094c9e9a667e4522aa7 (diff)
Assert expected size before unmarshalling
...to prevent panicking in case of failure. PiperOrigin-RevId: 354970257
Diffstat (limited to 'test/packetimpact')
-rw-r--r--test/packetimpact/tests/tcp_info_test.go6
1 files changed, 6 insertions, 0 deletions
diff --git a/test/packetimpact/tests/tcp_info_test.go b/test/packetimpact/tests/tcp_info_test.go
index b66e8f609..69275e54b 100644
--- a/test/packetimpact/tests/tcp_info_test.go
+++ b/test/packetimpact/tests/tcp_info_test.go
@@ -55,6 +55,9 @@ func TestTCPInfo(t *testing.T) {
info := linux.TCPInfo{}
infoBytes := dut.GetSockOpt(t, acceptFD, unix.SOL_TCP, unix.TCP_INFO, int32(linux.SizeOfTCPInfo))
+ if got, want := len(infoBytes), linux.SizeOfTCPInfo; got != want {
+ t.Fatalf("expected %T, got %d bytes want %d bytes", info, got, want)
+ }
binary.Unmarshal(infoBytes, usermem.ByteOrder, &info)
rtt := time.Duration(info.RTT) * time.Microsecond
@@ -93,6 +96,9 @@ func TestTCPInfo(t *testing.T) {
info = linux.TCPInfo{}
infoBytes = dut.GetSockOpt(t, acceptFD, unix.SOL_TCP, unix.TCP_INFO, int32(linux.SizeOfTCPInfo))
+ if got, want := len(infoBytes), linux.SizeOfTCPInfo; got != want {
+ t.Fatalf("expected %T, got %d bytes want %d bytes", info, got, want)
+ }
binary.Unmarshal(infoBytes, usermem.ByteOrder, &info)
if info.CaState != linux.TCP_CA_Loss {
t.Errorf("expected the connection to be in loss recovery, got: %v want: %v", info.CaState, linux.TCP_CA_Loss)