Windows error reporting for dll_load doesn't check for a null buffer

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: P3
    • 26
    • Affects Version/s: 8
    • Component/s: hotspot
    • b80
    • 6
    • b08
    • windows

      Library loading is performed by:

      void * os::dll_load(const char *name, char *ebuf, int ebuflen)

      where the `ebuf` buffer is used for producing error information if the loading fails. However on Windows the `ebuf` value is never checked for null but is used unconditionally e.g.

       // Read system error message into ebuf
        // It may or may not be overwritten below (in the for loop and just above)
        lasterror(ebuf, (size_t) ebuflen);
        ebuf[ebuflen - 1] = '\0';
        Events::log_dll_message(nullptr, "Loading shared library %s failed, error code %lu", name, errcode);
        log_info(os)("shared library load of %s failed, error code %lu", name, errcode);

        if (errcode == ERROR_MOD_NOT_FOUND) {
          strncpy(ebuf, "Can't find dependent libraries", ebuflen - 1);
          ebuf[ebuflen - 1] = '\0';
          JFR_ONLY(load_event.set_error_msg(ebuf);)
          return nullptr;
        }

      Whilst it seems a little odd to pass a null buffer and skip error reporting, that is what the JFR code does when loading some of its libraries:

      void IphlpDll::initialize(void) {
        _hModule = os::win32::load_Windows_dll("iphlpapi.dll", nullptr, 0);

      void PdhDll::initialize(void) {
        _hModule = os::win32::load_Windows_dll("pdh.dll", nullptr, 0);

      The Posix code correctly handles a null buffer.

      The code for this was added in JDK 6, but it was only in JDK 11 that JFR started passing the null buffers.

            Assignee:
            David Holmes
            Reporter:
            David Holmes
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: