summaryrefslogtreecommitdiffhomepage
path: root/pkg/abi
diff options
context:
space:
mode:
authorKevin Krakauer <krakauer@google.com>2019-04-03 12:59:27 -0700
committerShentubot <shentubot@google.com>2019-04-03 13:00:34 -0700
commit82529becaee6f5050cb3ebb4aaa7a798357c1cf1 (patch)
treef82a017a8b48ed6ee6dfbd78db74a55b3fbd56c5 /pkg/abi
parentc79e81bd27cd9cccddb0cece30bf47efbfca41b7 (diff)
Fix index out of bounds in tty implementation.
The previous implementation revolved around runes instead of bytes, which caused weird behavior when converting between the two. For example, peekRune would read the byte 0xff from a buffer, convert it to a rune, then return it. As rune is an alias of int32, 0xff was 0-padded to int32(255), which is the hex code point for ?. However, peekRune also returned the length of the byte (1). When calling utf8.EncodeRune, we only allocated 1 byte, but tried the write the 2-byte character ?. tl;dr: I apparently didn't understand runes when I wrote this. PiperOrigin-RevId: 241789081 Change-Id: I14c788af4d9754973137801500ef6af7ab8a8727
Diffstat (limited to 'pkg/abi')
-rw-r--r--pkg/abi/linux/tty.go20
1 files changed, 12 insertions, 8 deletions
diff --git a/pkg/abi/linux/tty.go b/pkg/abi/linux/tty.go
index e6f7c5b2a..bff882d89 100644
--- a/pkg/abi/linux/tty.go
+++ b/pkg/abi/linux/tty.go
@@ -14,10 +14,6 @@
package linux
-import (
- "unicode/utf8"
-)
-
const (
// NumControlCharacters is the number of control characters in Termios.
NumControlCharacters = 19
@@ -104,11 +100,19 @@ func (t *KernelTermios) FromTermios(term Termios) {
}
// IsTerminating returns whether c is a line terminating character.
-func (t *KernelTermios) IsTerminating(c rune) bool {
+func (t *KernelTermios) IsTerminating(cBytes []byte) bool {
+ // All terminating characters are 1 byte.
+ if len(cBytes) != 1 {
+ return false
+ }
+ c := cBytes[0]
+
+ // Is this the user-set EOF character?
if t.IsEOF(c) {
return true
}
- switch byte(c) {
+
+ switch c {
case disabledChar:
return false
case '\n', t.ControlCharacters[VEOL]:
@@ -120,8 +124,8 @@ func (t *KernelTermios) IsTerminating(c rune) bool {
}
// IsEOF returns whether c is the EOF character.
-func (t *KernelTermios) IsEOF(c rune) bool {
- return utf8.RuneLen(c) == 1 && byte(c) == t.ControlCharacters[VEOF] && t.ControlCharacters[VEOF] != disabledChar
+func (t *KernelTermios) IsEOF(c byte) bool {
+ return c == t.ControlCharacters[VEOF] && t.ControlCharacters[VEOF] != disabledChar
}
// Input flags.