RFR: 8305650: os::lasterror incorrectly truncates buffer in os_windows.cpp
    David Holmes 
    dholmes at openjdk.org
       
    Wed Apr  5 12:41:17 UTC 2023
    
    
  
On Wed, 5 Apr 2023 11:36:30 GMT, Julian Waters <jwaters at openjdk.org> wrote:
> n in os::lasterror defined by os_windows.cpp is only the length of the string's actual character data, not accounting for the null character terminating the string. We should terminate the n + 1 character, not the n'th character
Changes requested by dholmes (Reviewer).
src/hotspot/os/windows/os_windows.cpp line 2153:
> 2151:     if (n >= len) n = len - 1;
> 2152:     strncpy(buf, s, n);
> 2153:     buf[n + 1] = '\0';
If n was >= len then you are now indexing outside of buf!
-------------
PR Review: https://git.openjdk.org/jdk/pull/13350#pullrequestreview-1372823049
PR Review Comment: https://git.openjdk.org/jdk/pull/13350#discussion_r1158462652
    
    
More information about the hotspot-runtime-dev
mailing list