From f01cf72d6de371e2cb82e98443aeab36dbfe9d7b Mon Sep 17 00:00:00 2001 From: "Matthew R. Wilson" Date: Sun, 27 Dec 2020 01:31:20 -0800 Subject: [PATCH] Add logging code for out-of-bounds buffer addresses --- response.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/response.go b/response.go index 99edf6e..0971608 100644 --- a/response.go +++ b/response.go @@ -6,7 +6,9 @@ package go3270 import ( "bytes" + "fmt" "net" + "os" ) // Response encapsulates data received from a 3270 client in response to the @@ -210,6 +212,17 @@ func handleField(addr int, value []byte, fm fieldmap, values map[string]string) // decodeBufAddr decodes a raw 2-byte encoded buffer address and returns the // integer value of the address (i.e. 0-1919) func decodeBufAddr(raw [2]byte) int { + if decodes[raw[0]]<<6 > 254 { + fmt.Fprintf(os.Stderr, + "UNEXPECTED VALUE: decodeBufAddr got raw value of %02x %02x\n", + raw[0], raw[1]) + } + if decodes[raw[1]] > 254 { + fmt.Fprintf(os.Stderr, + "UNEXPECTED VALUE: decodeBufAddr got raw value of %02x %02x\n", + raw[0], raw[1]) + } + hi := decodes[raw[0]] << 6 lo := decodes[raw[1]] return hi | lo