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

strerror() function is not thread-safe

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 9
    • Fix Version/s: 10
    • Component/s: hotspot
    • Labels:
      None

      Backports

        Description

        In many places in the VM code if we detect an error from a library call we use strerror(errno) to produce a human-readable description of the error. Unfortunately strerror may not be thread-safe, particularly when the content is localized, due to use of a static buffer:

        DESCRIPTION
               The strerror() function returns a pointer to a string that describes the error code passed in the argument errnum, possibly using the LC_MESSAGES part of the current locale to select the appropriate language. This string must not be modified by the application, but may be modified by a subsequent call to perror(3) or strerror(). No library function will modify this string.

               The strerror_r() function is similar to strerror(), but is thread safe. This function is available in two versions: an XSI-compliant version specified in POSIX.1-2001 (available since glibc 2.3.4), and a GNU-specific version (available since glibc 2.0).

        ----

        Switching to strerror_r seems reasonable, but some usage contexts make it difficult to define a local buffer - in particular unified-logging expressions where we don't want to have to define the buffer if logging is not enabled. Simple wrapping of the call also doesn't work as we can't use the buffer after the call returns.

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  stuefe Thomas Stuefe
                  Reporter:
                  dholmes David Holmes
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  5 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: