RFR: 8325002: Exceptions::fthrow needs to ensure it truncates to a valid utf8 string [v5]

Daniel Jeliński djelinski at openjdk.org
Tue Jul 30 08:42:37 UTC 2024


On Tue, 30 Jul 2024 05:41:08 GMT, David Holmes <dholmes 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.
>
> David Holmes has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Fix off-by-one error

src/hotspot/share/utilities/exceptions.cpp line 278:

> 276:   if (ret == -1 || ret >= max_msg_size) {
> 277:     int len = (int) strlen(msg);
> 278:     if (len > 0) {

`truncate` asserts that len>5, you might need to adjust that.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/20345#discussion_r1696567086


More information about the hotspot-dev mailing list