Skip to content

Commit 1052996

Browse files
Merge pull request #632 from faisalmumtaz89/decrqss-nonascii-upstream
Guard the unknown-DECRQSS log against a non-ASCII payload
2 parents bf6aa3e + a491698 commit 1052996

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

Sources/SwiftTerm/Terminal.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1119,7 +1119,7 @@ open class Terminal {
11191119
default:
11201120
ok = 0 // this means the request is not valid, report that to the host.
11211121
// invalid: DCS 0 $ r Pt ST (xterm)
1122-
terminal.log ("Unknown DCS + \(newData!)")
1122+
terminal.log ("Unknown DCS + \(newData ?? "")")
11231123
// Do not report 'newData', because it can be exploited
11241124
// see https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=510030
11251125
result = ""

Tests/SwiftTermTests/DcsTests.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,18 @@ final class DcsTests {
5353
// Response format: DCS 1 $ r <SGR params> m ST
5454
}
5555

56+
/// DECRQSS with a non-ASCII payload byte: the payload does not decode as
57+
/// ASCII, and the unknown-request branch must answer rather than crash.
58+
@Test func testDecrqssNonAsciiPayload() {
59+
let h = HeadlessTerminal(queue: SwiftTermTests.queue) { _ in }
60+
let t = h.terminal!
61+
62+
// DECRQSS (ESC P $ q <0xA0> ESC \) with a non-ASCII payload byte.
63+
t.feed(byteArray: [0x1b, 0x50, 0x24, 0x71, 0xa0, 0x1b, 0x5c])
64+
65+
// Should not crash.
66+
}
67+
5668
/// Test DECRQSS for DECSTBM (scrolling region)
5769
@Test func testDecrqssDecstbm() {
5870
let h = HeadlessTerminal(queue: SwiftTermTests.queue) { _ in }

0 commit comments

Comments
 (0)