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

Hotspot error reporting always uses not thread-safe function (ctime)

    Details

    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      linux

      Description

      A DESCRIPTION OF THE PROBLEM :
       On error reporting, Hotspot calls the ctime() function to transform date and time. However, this function is not thread-safe function.
       Other functions that transform date and time were replaced to thread-safe functions (e.g. localtime_r()). In additional, ctime() is marked as obsolete, and recommended to the use of strftime() instead. And strftime() is already called to transform time zone.
       Therefore, to print time information, there should be used strftime() only at first, and should be used ctime_r() only if localtime_pd() returns null..

      src/hotspot/share/runtime/os.cpp
      ---------- BEGIN SOURCE ----------
      void os::print_date_and_time(outputStream *st, char* buf, size_t buflen) {
        const int secs_per_day = 86400;
        const int secs_per_hour = 3600;
        const int secs_per_min = 60;

        time_t tloc;
        (void)time(&tloc);
        char* timestring = ctime(&tloc); // ctime adds newline.
        // edit out the newline
        char* nl = strchr(timestring, '\n');
        if (nl != NULL) {
          *nl = '\0';
        }

        struct tm tz;
        if (localtime_pd(&tloc, &tz) != NULL) {
          ::strftime(buf, buflen, "%Z", &tz);
          st->print("Time: %s %s", timestring, buf);
        } else {
          st->print("Time: %s", timestring);
        }
      ---------- END SOURCE ----------



      FREQUENCY : always


        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: