RFR: JDK-8327986: ASAN reports use-after-free in DirectivesParserTest.empty_object_vm

Daniel Jeliński djelinski at openjdk.org
Wed Mar 13 09:19:14 UTC 2024


On Wed, 13 Mar 2024 08:27:27 GMT, Thomas Stuefe <stuefe at openjdk.org> wrote:

>> test/hotspot/gtest/compiler/test_directivesParser.cpp line 39:
>> 
>>> 37:   // These tests require the "C" locale to correctly parse decimal values
>>> 38:   DirectivesParserTest() : _locale(os::strdup(setlocale(LC_NUMERIC, nullptr), mtTest)) {
>>> 39:     setlocale(LC_NUMERIC, "C");
>> 
>> Would it fix the issue if we did this instead?
>> 
>> Suggestion:
>> 
>>   DirectivesParserTest() : _locale(setlocale(LC_NUMERIC, "C")) {
>> 
>> 
>> seems to me that the string returned by setlocale is only valid until the next setlocale call, and currently we call setlocale twice in the constructor, and save the result of the first call.
>
> No. The first setlocate call returns the pointer to the last locale, which becomes invalid. Changing the input string on the first setlocale call won't change that.

Ah. I was misled by the `setlocale` docs:
> The string returned is such that a subsequent call with that string and its associated category will restore that part of the process's locale.

apparently it doesn't restore them _to the previous value_, as I incorrectly assumed.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/18235#discussion_r1522820269


More information about the hotspot-compiler-dev mailing list