[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.
This commit is contained in:
Ryan Prichard
2024-02-26 13:23:30 -08:00
committed by GitHub
parent 99335a646b
commit acdd36e677
2 changed files with 5 additions and 4 deletions

View File

@@ -5541,7 +5541,7 @@ Node *AbstractManglingParser<Alloc, Derived>::parseFloatingLiteral() {
return nullptr;
std::string_view Data(First, N);
for (char C : Data)
if (!std::isxdigit(C))
if (!(C >= '0' && C <= '9') && !(C >= 'a' && C <= 'f'))
return nullptr;
First += N;
if (!consumeIf('E'))

View File

@@ -30222,9 +30222,8 @@ struct FPLiteralCase {
}},
#endif
#if LDBL_FP128
// This was found by libFuzzer+HWASan on aarch64 Android.
{"1\006ILeeeEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE",
{"\x6<-0x1.cecececececececececececececep+11983L>"}},
// A 32-character FP literal of long double type
{"3FooILeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeEE", {"Foo<-0x1.eeeeeeeeeeeeeeeeeeeeeeeeeeeep+12015L>"}},
#endif
};
const unsigned NF = sizeof(fp_literal_cases) / sizeof(fp_literal_cases[0]);
@@ -30238,6 +30237,8 @@ const char* invalid_cases[] =
"NSoERj5E=Y1[uM:ga",
"Aon_PmKVPDk7?fg4XP5smMUL6;<WsI_mgbf23cCgsHbT<l8EE\0uVRkNOoXDrgdA4[8IU>Vl<>IL8ayHpiVDDDXTY;^o9;i",
"_ZNSt16allocator_traitsISaIN4llvm3sys2fs18directory_iteratorEEE9constructIS3_IS3_EEEDTcl12_S_constructfp_fp0_spcl7forwardIT0_Efp1_EEERS4_PT_DpOS7_",
"3FooILdaaaaaaaaaaAAAAaaEE",
"3FooILdaaaaaaaaaaaaaaEE",
#if !LDBL_FP80
"_ZN5test01hIfEEvRAcvjplstT_Le4001a000000000000000E_c",
#endif