cmd/age: reject invalid UTF-8 terminal output
Reported by Joe Doyle of Trail of Bits.
This commit is contained in:
parent
3604609d98
commit
de96c8e8e1
1 changed files with 2 additions and 1 deletions
|
|
@ -19,6 +19,7 @@ import (
|
|||
"slices"
|
||||
"strings"
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
|
||||
"filippo.io/age"
|
||||
"filippo.io/age/agessh"
|
||||
|
|
@ -295,7 +296,7 @@ func main() {
|
|||
// Buffer the output to check it's printable.
|
||||
out = buf
|
||||
defer func() {
|
||||
if bytes.ContainsFunc(buf.Bytes(), func(r rune) bool {
|
||||
if !utf8.Valid(buf.Bytes()) || bytes.ContainsFunc(buf.Bytes(), func(r rune) bool {
|
||||
return r != '\n' && r != '\r' && r != '\t' && unicode.IsControl(r)
|
||||
}) {
|
||||
errorWithHint("refusing to output binary to the terminal",
|
||||
|
|
|
|||
Loading…
Reference in a new issue