RFR: 8347707: Standardise the use of os::snprintf and os::snprintf_checked [v2]

Dean Long dlong at openjdk.org
Thu Aug 21 07:48:57 UTC 2025


On Thu, 21 Aug 2025 06:35:44 GMT, David Holmes <dholmes at openjdk.org> wrote:

>> src/hotspot/os/aix/os_aix.cpp line 1055:
>> 
>>> 1053:     if (ebuf != nullptr && ebuflen > 0) {
>>> 1054:       os::snprintf_checked(ebuf, ebuflen - 1, "%s, LIBPATH=%s, LD_LIBRARY_PATH=%s : %s",
>>> 1055:                            filename, ::getenv("LIBPATH"), ::getenv("LD_LIBRARY_PATH"), error_report);
>> 
>> Suggestion:
>> 
>>       (void) os::snprintf(ebuf, ebuflen - 1, "%s, LIBPATH=%s, LD_LIBRARY_PATH=%s : %s",
>>                            filename, ::getenv("LIBPATH"), ::getenv("LD_LIBRARY_PATH"), error_report);
>> 
>> This could easily truncate, based on LIBPATH and LD_LIBRARY_PATH.
>
> Yes but again if that happens during testing we need to know and fix the buffer size to get the non-truncated values.

In this case the buffer size comes from shared code.  Whatever size we choose for the static buffer, we can trigger the assert by setting LIBPATH and LD_LIBRARY_PATH to very long strings.  This is just the error message, so it might be OK to truncate it.  Otherwise we could need to allocate the buffer using malloc.

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

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


More information about the hotspot-dev mailing list