Skip to content

Commit acdd36e

Browse files
authored
[ItaniumDemangle] reject A-F in FP literals (#82864)
The Itanium C++ ABI specifies that FP literals are encoded using a lowercase hexadecimal string. Previously, libc++abi allowed uppercase A-F characters but decoded them by subtracting 'a' from them, producing negative digit values. It is especially confusing to accept an 'E' digit because 'E' marks the end of the FP literal.
1 parent 99335a6 commit acdd36e

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

libcxxabi/src/demangle/ItaniumDemangle.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5541,7 +5541,7 @@ Node *AbstractManglingParser<Alloc, Derived>::parseFloatingLiteral() {
55415541
return nullptr;
55425542
std::string_view Data(First, N);
55435543
for (char C : Data)
5544-
if (!std::isxdigit(C))
5544+
if (!(C >= '0' && C <= '9') && !(C >= 'a' && C <= 'f'))
55455545
return nullptr;
55465546
First += N;
55475547
if (!consumeIf('E'))

libcxxabi/test/test_demangle.pass.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30222,9 +30222,8 @@ struct FPLiteralCase {
3022230222
}},
3022330223
#endif
3022430224
#if LDBL_FP128
30225-
// This was found by libFuzzer+HWASan on aarch64 Android.
30226-
{"1\006ILeeeEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE",
30227-
{"\x6<-0x1.cecececececececececececececep+11983L>"}},
30225+
// A 32-character FP literal of long double type
30226+
{"3FooILeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeEE", {"Foo<-0x1.eeeeeeeeeeeeeeeeeeeeeeeeeeeep+12015L>"}},
3022830227
#endif
3022930228
};
3023030229
const unsigned NF = sizeof(fp_literal_cases) / sizeof(fp_literal_cases[0]);
@@ -30238,6 +30237,8 @@ const char* invalid_cases[] =
3023830237
"NSoERj5E=Y1[uM:ga",
3023930238
"Aon_PmKVPDk7?fg4XP5smMUL6;<WsI_mgbf23cCgsHbT<l8EE\0uVRkNOoXDrgdA4[8IU>Vl<>IL8ayHpiVDDDXTY;^o9;i",
3024030239
"_ZNSt16allocator_traitsISaIN4llvm3sys2fs18directory_iteratorEEE9constructIS3_IS3_EEEDTcl12_S_constructfp_fp0_spcl7forwardIT0_Efp1_EEERS4_PT_DpOS7_",
30240+
"3FooILdaaaaaaaaaaAAAAaaEE",
30241+
"3FooILdaaaaaaaaaaaaaaEE",
3024130242
#if !LDBL_FP80
3024230243
"_ZN5test01hIfEEvRAcvjplstT_Le4001a000000000000000E_c",
3024330244
#endif

0 commit comments

Comments
 (0)