Skip to content

Commit d4c1642

Browse files
authored
[LLVM][Demangle] Fix MS Demangler to be stricter about wide string literals (llvm#134483)
Static analysis detected that Demangler::demangleStringLiteral had a potential overflow if not checking StringByteSize properly. Added check to ensure that for wide string it is always even and that there were the byte count did not mismatch the actual size of the literal. Fixes: llvm#129970
1 parent 7aedeba commit d4c1642

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

llvm/docs/ReleaseNotes.md

+2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ Changes to LLVM infrastructure
7070

7171
* Removed support for target intrinsics being defined in the target directories
7272
themselves (i.e., the `TargetIntrinsicInfo` class).
73+
* Fix Microsoft demangling of string literals to be stricter
74+
(#GH129970))
7375

7476
Changes to building LLVM
7577
------------------------

llvm/lib/Demangle/MicrosoftDemangle.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -1374,6 +1374,11 @@ Demangler::demangleStringLiteral(std::string_view &MangledName) {
13741374
Result->IsTruncated = true;
13751375

13761376
while (!consumeFront(MangledName, '@')) {
1377+
// For a wide string StringByteSize has to have an even length.
1378+
if (StringByteSize % 2 != 0)
1379+
goto StringLiteralError;
1380+
if (StringByteSize == 0)
1381+
goto StringLiteralError;
13771382
if (MangledName.size() < 2)
13781383
goto StringLiteralError;
13791384
wchar_t W = demangleWcharLiteral(MangledName);

llvm/test/Demangle/invalid-manglings.test

+24
Original file line numberDiff line numberDiff line change
@@ -379,3 +379,27 @@
379379
; CHECK-EMPTY:
380380
; CHECK-NEXT: .?AUBase@@@8
381381
; CHECK-NEXT: error: Invalid mangled name
382+
383+
; Begin GH129970
384+
385+
??_C@_12EEHFKJGG@?$AAt?$AAe?$AAx@
386+
; CHECK-EMPTY:
387+
; CHECK-NEXT: ??_C@_12EEHFKJGG@?$AAt?$AAe?$AAx@
388+
; CHECK-NEXT: error: Invalid mangled name
389+
390+
??_C@_16EEHFKJGG@?$AAt?$AAe?$AAx@
391+
; CHECK-EMPTY:
392+
; CHECK-NEXT: ??_C@_16EEHFKJGG@?$AAt?$AAe?$AAx@
393+
; CHECK-NEXT: error: Invalid mangled name
394+
395+
??_C@_18EEHFKJGG@?$AAt?$AAe?$AAx@
396+
; CHECK-EMPTY:
397+
; CHECK-NEXT: ??_C@_18EEHFKJGG@?$AAt?$AAe?$AAx@
398+
; CHECK-NEXT: error: Invalid mangled name
399+
400+
??_C@_15EEHFKJGG@?$AAt?$AAe?$AAx?$AAx@
401+
; CHECK-EMPTY:
402+
; CHECK-NEXT: ??_C@_15EEHFKJGG@?$AAt?$AAe?$AAx?$AAx@
403+
; CHECK-NEXT: error: Invalid mangled name
404+
405+
; End GH129970

0 commit comments

Comments
 (0)