JDK-8214777 : Avoid some GCC 8.X strncpy() errors in HotSpot
  • Type: Bug
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 8,11,12,13
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2018-12-04
  • Updated: 2019-10-12
  • Resolved: 2019-02-22
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 11 JDK 13
11.0.5Fixed 13 b10Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Description
Gcc 8 has strict (and sometimes buggy) tests for strncpy() misuse.

A common pattern in the JDK is:

    const size_t not_impl_len = strlen(not_impl);
    *str = NEW_C_HEAP_ARRAY(char, not_impl_len+1, mtTracing);
    strncpy(*str, not_impl, not_impl_len);
    (*str)[not_impl_len] = '\0';

More efficient code that does not cause GCC warnings would use strncpy()
to add the trailing null, resulting in shorter code:

     strncpy(*str, not_impl, not_impl_len);
    (*str)[not_impl_len] = '\0';

becomes:

    strncpy(*str, not_impl, not_impl_len+1);

(found by compiling with GCC 8.1)
Comments
Fix Request I'd like to request a backport of this fix to 11u. This fix improves buildability with newer versions of GCC and also Clang. The fix does not apply cleanly; I have a modifed patch [1], and have put out an RFR [2]. JDK-8219583 [3] may be required to avoid compilation errors in some windows toolchains; I request that this fix be pushed first, then JDK-8219583 [4] right after. [1] modified patch http://cr.openjdk.java.net/~stooke/webrevs/jdk-8214777-jdk11u/webrev.00/ [2] rfr: http://mail.openjdk.java.net/pipermail/jdk-updates-dev/2019-August/001664.html [3] https://bugs.openjdk.java.net/browse/JDK-8219583 [4] https://mail.openjdk.java.net/pipermail/jdk-updates-dev/2019-August/001675.html
19-08-2019

I'm not working on it. Simon has done some work on this: http://mail.openjdk.java.net/pipermail/hotspot-runtime-dev/2018-December/031743.html Note that there wasn't really consensus whether this should be fixed at all: http://mail.openjdk.java.net/pipermail/hotspot-runtime-dev/2018-December/031774.html
18-02-2019

[~sgehwolf] (cc: [~dchuyko]) To avoid double/wasted work, note that I have pushed a few changes over the last few days, and was planning on sending out one more RFR early next week with some additional changes to hotspot code, something like this (though this exact version is still work in progress): http://cr.openjdk.java.net/~mikael/webrevs/gcc8.2-hotspot-strncpy/webrev.00/open/webrev/ Let me know if you're already working on some or all of these code changes and want to take ownership of it, otherwise I'll send something out next week.
16-02-2019

Assigning this one to Simon as he's author now.
14-02-2019

Assigning to myself on behalf of Simon Tooke
04-12-2018