Skip to content

Commit c377e8b

Browse files
committed
Demangler: Fix out-of-bounds read printing quoted high-bit characters.
If `char` is signed, then `c >> 4` produces a signed negative number when `c` has the high bit set, and `Hexdigit[c >> 4]` reads junk out of the memory right before `Hexdigit`. Change the code here to use `unsigned char`.
1 parent 1445314 commit c377e8b

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

lib/Demangling/NodePrinter.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,11 @@ static DemanglerPrinter &operator<<(DemanglerPrinter &printer,
7979
case '\n': printer << "\\n"; break;
8080
case '\r': printer << "\\r"; break;
8181
case '"': printer << "\\\""; break;
82-
case '\'': printer << '\''; break; // no need to escape these
8382
case '\0': printer << "\\0"; break;
8483
default:
85-
auto c = static_cast<char>(C);
86-
// Other ASCII control characters should get escaped.
87-
if (c < 0x20 || c == 0x7F) {
84+
auto c = static_cast<unsigned char>(C);
85+
// Other control or high-bit characters should get escaped.
86+
if (c < 0x20 || c >= 0x7F) {
8887
static const char Hexdigit[] = {
8988
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
9089
'A', 'B', 'C', 'D', 'E', 'F'

0 commit comments

Comments
 (0)