To take one example:
if (::FindClose(f) == 0) {
errno = ::GetLastError();
log_debug(os)("is_symbolic_link() failed to FindClose: GetLastError->%ld.", errno);
}
this code attempts to set `errno` so that a caller can check it upon error. However, if logging is enabled then the logging code can overwrite `errno` before the caller can check it! And this is not confined to logging statements - a lot of code does cleanup like `os:free(buf)` before returning and that too can (potentially) overwrite `errno`.
The use of `errno` in these API's needs to examined and if needed we have to preserve the value for the caller using `ErrnoPreserver` as is done in the non-Windows code (though that too should be audited).
This problem seems to have been introduced post JDK 21, but I have not pinned it down.
if (::FindClose(f) == 0) {
errno = ::GetLastError();
log_debug(os)("is_symbolic_link() failed to FindClose: GetLastError->%ld.", errno);
}
this code attempts to set `errno` so that a caller can check it upon error. However, if logging is enabled then the logging code can overwrite `errno` before the caller can check it! And this is not confined to logging statements - a lot of code does cleanup like `os:free(buf)` before returning and that too can (potentially) overwrite `errno`.
The use of `errno` in these API's needs to examined and if needed we have to preserve the value for the caller using `ErrnoPreserver` as is done in the non-Windows code (though that too should be audited).
This problem seems to have been introduced post JDK 21, but I have not pinned it down.
- relates to
-
JDK-8364816 GetLastError() in os_windows.cpp should not store value to errno
-
- Open
-