-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use GetTempPath2 API instead of GetTempPath #21
Conversation
I recommend adding a sentence in the PR description acknowledging there is code duplication and the reasoning |
@@ -1515,12 +1519,16 @@ int os::closedir(DIR *dirp) { | |||
// directory not the java application's temp directory, ala java.io.tmpdir. | |||
const char* os::get_temp_directory() { | |||
static char path_buf[MAX_PATH]; | |||
if (GetTempPath(MAX_PATH, path_buf) > 0) { | |||
if (_GetTempPath2A != nullptr) { | |||
if (_GetTempPath2A(MAX_PATH, path_buf) > 0) { | |||
return path_buf; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the code indentation here is not correct. Is it?
path_buf[0] = '\0'; | ||
} | ||
} | ||
else if (GetTempPath(MAX_PATH, path_buf) > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: move "else if" to "}" line.
@@ -321,6 +321,26 @@ SetupI18nProps(LCID lcid, char** language, char** script, char** country, | |||
return TRUE; | |||
} | |||
|
|||
// For dynamic lookup of GetTempPath2 API | |||
typedef DWORD (WINAPI *GetTempPath2WFnPtr)(DWORD, LPWSTR); | |||
static GetTempPath2WFnPtr _GetTempPath2W = NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the code should use "nullptr" instead of NULL? I'm OK with it being "NULL" if other places in the file also uses NULL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why all these leading "_" ? Is that a coding guideline for that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using NULL as it is C code and others are C++.
Created an upstream PR. |
https://bugs.openjdk.org/browse/JDK-8337408
Use the
GetTempPath2
APIs instead of theGetTempPath
APIs in native code across the OpenJDK repository to retrieve the temporary directory path, asGetTempPath2
provides enhanced security. WhileGetTempPath
may still function without errors, usingGetTempPath2
reduces the risk of potential exploits for users.The code is duplicated, and we cannot address this issue for the following reasons: