x/term: prevent invalid indexing into stRingBuffer

The exported method (*stRingBuffer).NthPreviousEntry does not correctly
handle arguments with negative values. A negative value will index
beyond slice boundaries in most cases (unless size = max = INT_MAX) and
cause an access violation at runtime.

This change adds a condition to return ok = false for all negatively
valued arguments, which is the same behavior that occurs with positively
valued arguments exceeding buffer length.

Adding the capability to index backwards (from the end of the slice)
does not seem like the intent of this method, and it would not improve
or simplify existing functionality. It would also be inconsistent with
the handling of positive values out-of-bounds.

Change-Id: Ib4113330f0044dd5b73c7d75c5cdcdd27d60ee77
GitHub-Last-Rev: fec355f53687dfbee962f611297355059efabd48
GitHub-Pull-Request: golang/term#8
Reviewed-on: https://go-review.googlesource.com/c/term/+/408754
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
1 file changed
tree: 85d2e7ce223453811db2e73aefc67a2b87dae515
  1. AUTHORS
  2. codereview.cfg
  3. CONTRIBUTING.md
  4. CONTRIBUTORS
  5. go.mod
  6. go.sum
  7. LICENSE
  8. PATENTS
  9. README.md
  10. term.go
  11. term_plan9.go
  12. term_test.go
  13. term_unix.go
  14. term_unix_bsd.go
  15. term_unix_other.go
  16. term_unsupported.go
  17. term_windows.go
  18. terminal.go
  19. terminal_test.go
README.md

Go terminal/console support

Go Reference

This repository provides Go terminal and console support packages.

Download/Install

The easiest way to install is to run go get -u golang.org/x/term. You can also manually git clone the repository to $GOPATH/src/golang.org/x/term.

Report Issues / Send Patches

This repository uses Gerrit for code changes. To learn how to submit changes to this repository, see https://golang.org/doc/contribute.html.

The main issue tracker for the term repository is located at https://github.com/golang/go/issues. Prefix your issue with “x/term:” in the subject line, so it is easy to find.