RFR: 8347707: Standardise the use of os::snprintf and os::snprintf_checked

David Holmes dholmes at openjdk.org
Thu Aug 21 06:33:51 UTC 2025


On Wed, 20 Aug 2025 22:59:51 GMT, Dean Long <dlong at openjdk.org> wrote:

>> src/hotspot/os/aix/attachListener_aix.cpp line 423:
>> 
>>> 421:     log_trace(attach)("Failed to find attach file: %s, trying alternate", fn);
>>> 422:     os::snprintf_checked(fn, sizeof(fn), "%s/.attach_pid%d",
>>> 423:                          os::get_temp_directory(), os::current_process_id());
>> 
>> This could fail if os::get_temp_directory() returns an extremely long path.  How about doing a truncation check like at line 354?
>
> Nevermind, same thing.  We would need to fix a lot of code if os::get_temp_directory() returned a pathologically long string.

I've changed line 352 as per Kim's comment above because `snprintf` followed by an assert for truncation is what `snprintf_checked` does.

Again the question to ask is: if we hit this during testing do we think it indicates we need to increase the buffer size. Again I am initially in the yes camp.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/26849#discussion_r2289987176


More information about the hotspot-dev mailing list