RFR: 8345012: os::build_agent_function_name potentially wastes a byte when allocating the buffer [v3]

David Holmes dholmes at openjdk.org
Thu Nov 28 12:38:45 UTC 2024


On Thu, 28 Nov 2024 07:21:57 GMT, Thomas Stuefe <stuefe at openjdk.org> wrote:

> I think there is a preexisting error in that `name_len`is fed as `size` parameter to `strncat`. Since the buffer is already partly filled at that point, we cannot use the full buffer size but should use the size of the remaining space in the buffer.

Thanks for looking at this @tstuefe . I will take a look at that - tomorrow.

> src/hotspot/os/posix/os_posix.cpp line 976:
> 
>> 974:    // Total buffer length to allocate - includes null terminator.
>> 975:   len = strlen(sym_name) + (need_underscore ? 1 : 0) + name_len + 1;
>> 976:   agent_entry_name = NEW_C_HEAP_ARRAY_RETURN_NULL(char, len, mtThread);
> 
> Preexisting: If we fail to allocate memory, we return NULL, which results in various places in confusing "cannot find agent function" messages. Maybe better would be a clear native oom exit here?

That kind of change in functionality is not a part of this PR.  Plus it is a moot point as we would never get a native OOM during VM init in any realistic circumstances.

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

PR Comment: https://git.openjdk.org/jdk/pull/22404#issuecomment-2506021574
PR Review Comment: https://git.openjdk.org/jdk/pull/22404#discussion_r1862098075


More information about the hotspot-runtime-dev mailing list