RFR: 8325002: Exceptions::fthrow needs to ensure it truncates to a valid utf8 string [v2]
David Holmes
dholmes at openjdk.org
Mon Jul 29 23:18:35 UTC 2024
On Mon, 29 Jul 2024 13:26:12 GMT, Daniel Jeliński <djelinski at openjdk.org> wrote:
>> David Holmes has updated the pull request incrementally with three additional commits since the last revision:
>>
>> - Fix logic for 4th byte of 6.
>> - Fix logic error and typo
>> - Ensure the buffer is > 5 bytes
>
> src/hotspot/share/utilities/exceptions.cpp line 275:
>
>> 273: // we may also have a truncated UTF-8 sequence. In such cases we need to fix the buffer so the UTF-8
>> 274: // sequence is valid.
>> 275: if ((ret == -1 || ret >= max_msg_size) && strlen(msg) > 0) {
>
> Do we need to check if `strlen(msg) == max_msg_size - 1`? If strlen is shorter, the bytes between the null terminator and max_msg_size are undefined, which might trigger an assertion while truncating.
In fact we know it may be shorter than `max_msg_size - 1` - that is what we get on macOS if the string is huge and exceeds `INT_MAX` causing `vsnprintf` to return -1. I originally had an assert that failed due to that.
I need to fix this case as well. <sigh>. Good catch.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/20345#discussion_r1696067908
More information about the hotspot-dev
mailing list