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

[windows] Missing error check for GetSystemDirectory in glass

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • jfx23
    • jfx22
    • javafx

      In RoActivation.cpp, we find:

          wchar_t path[MAX_PATH];
          wchar_t file[MAX_PATH];

          if (GetSystemDirectory(path, sizeof(path) / sizeof(wchar_t)) == 0) {
              return;
          }

      This is likely only a theoretical concern, but if the path to the system directory has more than "MAX_PATH-1" chars, "path" will be uninitialized, since the docs for GetSystemDirectory say:

      "If the length is greater than the size of the buffer, the return value is the size of the buffer required to hold the path, including the terminating null character."

      While we are at it, we should replace this with an explicit call to GetSystemDirectoryW (it's equivalent, given that we compile with /DUNICODE, but since we are explicitly using wchar_t we should also explicitly use the wide version of the function).

      We should also check the return value of wcscat_s in case the concatenation of "combase.dll" doesn't fit.

      Suggested fix:

          UNIT rval = GetSystemDirectoryW(path, sizeof(path) / sizeof(wchar_t)) == 0) {
          if (rval == 0 || rval >= sizeof(path) / sizeof(wchar_t)) {
              return;
          }

          ...

          memcpy_s(file, sizeof(file), path, sizeof(path));
          if (wcscat_s(file, MAX_PATH-1, L"\\combase.dll") != 0) {
              return;
          }

            lkostyra Lukasz Kostyra
            kcr Kevin Rushforth
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: