RFR: 8305650: os::lasterror incorrectly truncates buffer in os_windows.cpp

Julian Waters jwaters at openjdk.org
Wed Apr 5 13:51:17 UTC 2023


On Wed, 5 Apr 2023 13:37:50 GMT, Julian Waters <jwaters at openjdk.org> wrote:

>> n is always meant to be the length of the buffer data without the null terminator. The check there is meant to enforce exactly that, it sets n = len - 1 because len is a parameter passed to lasterror, and is the size of the buffer the caller handed us. len is supposed to also include space for the null terminator while n is only the length of the actual character data, which is why the - 1 check is there
>
> Unless os::lasterror's len parameter is not supposed to include space for the null terminator, but I couldn't find any documentation or comment that says so. But if that were the case, then this whole code segment would be wrong, not just my change
> 
> Ahh, the joys of working with Windows error handling :)

Nevermind, just checked the POSIX version and it also has this flaw, so it's not just Windows

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

PR Review Comment: https://git.openjdk.org/jdk/pull/13350#discussion_r1158547633


More information about the hotspot-runtime-dev mailing list