Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8366272

Windows os::xxx API's do not manage errno correctly

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • 26
    • hotspot
    • None
    • windows

      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.

            Unassigned Unassigned
            dholmes David Holmes
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: