JDK-8166372 : Improve readdir_r buffer handling in TimeZone_md.c
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util:i18n
  • Priority: P5
  • Status: Resolved
  • Resolution: Won't Fix
  • Submitted: 2016-09-20
  • Updated: 2018-05-08
  • Resolved: 2018-05-08
Related Reports
Relates :  
Relates :  
Description
JDK-8165936 fixed a potential buffer overflow in TimeZone_md.c, but broke Solaris, which was fixed with JDK-8166148. The code now imposes a minimum buffer size of 1024 bytes for the readdir_r buffer.

A better way would be to just rely on pathconf():
- if pathconf() returns an error, return an error as well
- Otherwise use the length pathconf() returned, but use a canary at the end of the buffer to check for buffer overflows.

The latter point is important because readdir_r in combination with pathconf is unsafe, see e.g. https://womble.decadent.org.uk/readdir_r-advisory.html
Comments
Closing the issue per the comment above.
08-05-2018

This will be rendered moot by JDK-8202794.
08-05-2018

Note that readdir_r is used in multiple places in the JDK libraries. * java.base/unix/native/libjava/TimeZone_md.c * java.base/unix/native/libjava/UnixFileSystem_md.c * java.base/unix/native/libnio/fs/UnixNativeDispatcher.c * jdk.management/unix/native/libmanagement_ext/OperatingSystemImpl.c Presumably, all these should be turned into readdir.
03-05-2018

Wow, this is still open... But these seem to be readdir_r days :) It was just proposed to revert readdir_r back to readdir in the hotspot, see https://bugs.openjdk.java.net/browse/JDK-8202353. I think that makes sense. Should we do this for the JDK libraries too? In that case, we can get rid of this bug.
27-04-2018

When I cross-compile aarch64 on x64, that uses a newer version of gcc, I get an error readdir error on: src/java.base/unix/native/libjava/TimeZone_md.c:150:5: error: 'readdir64_r' is deprecated [-Werror=deprecated-declarations] while (readdir64_r(dirp, entry, &dp) == 0 && dp != NULL) { ^~~~~ and src/java.base/unix/native/libjava/UnixFileSystem_md.c:342:5: error: 'readdir64_r' is deprecated [-Werror=deprecated-declarations] while ((readdir64_r(dir, ptr, &result) == 0) && (result != NULL)) { ^~~~~ Can this bug fix it while you're there? thanks.
27-04-2018