RFR: 8325002: Exceptions::fthrow needs to ensure it truncates to a valid utf8 string
David Holmes
dholmes at openjdk.org
Fri Jul 26 21:37:43 UTC 2024
On Fri, 26 Jul 2024 05:23:28 GMT, Thomas Stuefe <stuefe at openjdk.org> wrote:
>> Exceptions::fthrow uses a 1024 byte buffer to format the incoming exception message string, but this may not be large enough, leading to truncation. However, we should ensure we truncate to a valid UTF8 sequence.
>>
>> The process is explained in the code. Thanks to @RogerRiggs and @djelinski for their suggestions on how to tackle this.
>>
>> Testing:
>> - new gtest exercises the truncation code with the different possibilities for bad truncation
>> - tiers 1-3 sanity testing
>>
>> Thanks.
>
> src/hotspot/share/utilities/exceptions.cpp line 276:
>
>> 274: // sequence is valid.
>> 275: if ((ret == -1 || ret >= max_msg_size) && strlen(msg) > 0) {
>> 276: assert(msg[max_msg_size - 1] == '\0', "should be null terminated");
>
> Would this always be true? For a formatting error, too?
> Maybe just to be sure, instead of asserting set the last byte to zero.
vsnprintf is supposed to guarantee it, and os::vsnprint does IIRC, so this is just a sanity check.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/20345#discussion_r1693624938
More information about the hotspot-dev
mailing list