Skip to content

Commit 6ff55fb

Browse files
committed
syntax: fix a mksh Quote edge case found by fuzzing
Our check for 16-bit runes on mksh was wrong; we thought we could quote 0xFFFE and 0xFFFF, but we can't. Fix that, and quote the man page properly.
1 parent 92eab20 commit 6ff55fb

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

syntax/quote.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,16 +138,17 @@ func Quote(s string, lang LangVariant) (string, error) {
138138
case r > utf8.MaxRune:
139139
// Not a valid Unicode code point?
140140
return "", &QuoteError{ByteOffset: offs, Message: quoteErrRange}
141+
case lang == LangMirBSDKorn && r > 0xFFFD:
142+
// From the CAVEATS section in R59's man page:
143+
//
144+
// mksh currently uses OPTU-16 internally, which is the same as
145+
// UTF-8 and CESU-8 with 0000..FFFD being valid codepoints.
146+
return "", &QuoteError{ByteOffset: offs, Message: quoteErrMksh}
141147
case r < 0x10000:
142148
// \uXXXX, fixed at four hexadecimal characters.
143149
fmt.Fprintf(&b, "\\u%04x", r)
144150
default:
145151
// \UXXXXXXXX, fixed at eight hexadecimal characters.
146-
if lang == LangMirBSDKorn {
147-
// mksh seems to lack support for codepoints above 16 bits?
148-
// See the CAVEATS section in R59.
149-
return "", &QuoteError{ByteOffset: offs, Message: quoteErrMksh}
150-
}
151152
fmt.Fprintf(&b, "\\U%08x", r)
152153
}
153154
rem = rem[size:]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
go test fuzz v1
2+
string("\uffff")
3+
byte('\x02')

0 commit comments

Comments
 (0)