mirror of
https://github.com/FiloSottile/age.git
synced 2026-09-04 15:17:04 +00:00
cmd/age: reject invalid UTF-8 terminal output
Reported by Joe Doyle of Trail of Bits.
This commit is contained in:
+2
-1
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user