JDK-8205201 : Problematic strncpy usage causes compiler warning on Fedora 28
  • Type: Bug
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 11
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2018-06-19
  • Updated: 2021-08-03
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.
Other
tbdUnresolved
Related Reports
Relates :  
Description
/home/pr/sources/jdk/src/hotspot/os/posix/os_posix.cpp: In static member function ���static int os::create_file_for_heap(const char*)���:
/home/pr/sources/jdk/src/hotspot/os/posix/os_posix.cpp:172:16: error: ���char* strncpy(char*, const char*, size_t)��� specified bound depends on the length of the source argument [-Werror=stringop-overflow=]
   (void)strncpy(fullname, dir, strlen(dir)+1);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/pr/sources/jdk/src/hotspot/os/posix/os_posix.cpp:172:38: note: length computed here
   (void)strncpy(fullname, dir, strlen(dir)+1);
                                ~~~~~~^~~~~
/home/pr/sources/jdk/src/hotspot/os/posix/os_posix.cpp:173:16: error: ���char* strncat(char*, const char*, size_t)��� specified bound depends on the length of the source argument [-Werror=stringop-overflow=]
   (void)strncat(fullname, name_template, strlen(name_template));
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1plus: all warnings being treated as errors

It seems the limit is expected/required to be based on the size of the destination buffer rather than the source buffer. Which superficially seems reasonable, but it depends on whether you have sized your destination buffer based on the source size already. So these warnings could be false positives and we may need to make this a build issue and disable the warnings.
Comments
The current work-around is to configure with "--disable-warnings-as-errors".
05-07-2018

Note that one way to reproduce this warning is to use Fedora 28 and build OpenJDK. Fedora 28 has gcc 8.1.1: $ gcc --version gcc (GCC) 8.1.1 20180502 (Red Hat 8.1.1-1) Copyright (C) 2018 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See also: https://gcc.gnu.org/onlinedocs/gcc-8.1.0/gcc/Warning-Options.html#index-Wstringop-overflow
19-06-2018