JDK-8140482 : Various minor code improvements (runtime)
  • Type: Bug
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 8,9
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2015-10-26
  • Updated: 2024-06-18
  • Resolved: 2015-11-10
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 9
9 b94Fixed
Related Reports
Relates :  
Description
SAPs quality process requires a coverity scan. This change contains improvements resulting from this. 


Details:

libproc_impl.c:
Do strncpy in case getenv returned a bad string.
Strcat could overflow the buffer. Use strncat instead.

ps_core.c:
Pread not necesarrily terminates interp_name which is printed thereafter.
Increase buffer size by 1 and add '\0'.

stubRoutines_x86.cpp:
Cast to proper type. This way, left and right of '&' have the same type.

attachListener_linux.cpp:
Read does not terminate buf. Size for '\0' is already considered.

os_linux.cpp:
Array sigflags[] has size MAXSIGNUM==32.  _NSIG is bigger than 
MAXSIGNUM (_NSIG == 65 on my machine).
sig is checked to be smaller than _NSIG. Later, in set_our_sigflags(), 
sig is used to access sigflags[MAXSIGNUM] which can overflow the array.
Should we also increase MAXSIGNUM?
os::get_core_path(): read does not terminate string, but strlen is 
called on it.  The size already forsees one char for the '\0' byte.

codeBuffer.cpp:
New_capacity is not initialized. Figure_expanded_capacities() handles this
correctly, but initializing this is cheep and safe.

dict.cpp:
If j-- is executed for j==0, the loop aborts because j is unsigned (0-- >= b->_cnt).
Instead, only do j++ if necessary.

generateOopMap.cpp:
Idx is read from String. This is only called with constant strings, so compare
should be folded away by optimizing compilers if inlined.

deoptimization.cpp:
If buflen == 0, buf[-1] is accessed.

task.cpp:
Fatal can return if -XX:SuppressErrorAt is used.  Just don't access the 
array in this case.

attachListener.hpp:
Do strncpy to not overflow buffer. Don't write more chars than before.

heapDumper.cpp:
strncpy does not null terminate.

memoryService.cpp:
Initialization missing.

xmlstream.cpp:
Copy into fixed size buffer could overflow.  Use strncat instead.

Comments
[~shade] Possibly. Has it been reviewed? Both fixes, JDK-8210836 and JDK-8140482 (this one) are nice to have, though.
20-08-2020

[~sgehwolf, ~gnu_andrew] Had this fallen through the cracks for 8u? I think we want this to get JDK-8210836 cleanly.
20-08-2020

RFR(8u): https://mail.openjdk.java.net/pipermail/hotspot-dev/2018-November/035349.html
29-07-2019

URL: http://hg.openjdk.java.net/jdk9/jdk9/hotspot/rev/cd86b5699825 User: lana Date: 2015-11-25 21:18:08 +0000
25-11-2015

URL: http://hg.openjdk.java.net/jdk9/hs-rt/hotspot/rev/cd86b5699825 User: sspitsyn Date: 2015-11-10 06:52:56 +0000
10-11-2015