From f28f85d87be545e5ae0e2e64180f529cdeaa9517 Mon Sep 17 00:00:00 2001 From: Filippo Valsorda Date: Wed, 25 Mar 2020 01:29:30 -0400 Subject: [PATCH] internal/format: require recipients and arguments not to be empty Also updated the spec to clarify that arbitrary strings can't be empty. --- internal/format/format.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/internal/format/format.go b/internal/format/format.go index a74e031..d20bfbf 100644 --- a/internal/format/format.go +++ b/internal/format/format.go @@ -151,6 +151,11 @@ func Parse(input io.Reader) (*Header, io.Reader, error) { if prefix != string(recipientPrefix) || len(args) < 1 { return nil, nil, errorf("malformed recipient: %q", line) } + for _, a := range args { + if !isValidString(a) { + return nil, nil, errorf("malformed recipient: %q", line) + } + } r.Type = args[0] r.Args = args[1:] h.Recipients = append(h.Recipients, r) @@ -192,3 +197,15 @@ func splitArgs(line []byte) (string, []string) { parts := strings.Split(l, " ") return parts[0], parts[1:] } + +func isValidString(s string) bool { + if len(s) == 0 { + return false + } + for _, c := range s { + if c < 33 || c > 126 { + return false + } + } + return true +}