Skip to content
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

Fix use after free bug in Port::omrfile_stat #3670

Merged
merged 1 commit into from
Mar 20, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 12 additions & 7 deletions tools/tracegen/Port.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2014, 2018 IBM Corp. and others
* Copyright (c) 2014, 2019 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -266,6 +266,7 @@ Port::omrfile_stat(const char *path, unsigned int flags, struct J9FileStat *buf)
DWORD result;
wchar_t unicodeBuffer[UNICODE_BUFFER_SIZE];
wchar_t *unicodePath;
RCType rc = RC_OK;

if (NULL == path || NULL == buf) {
return RC_FAILED;
Expand All @@ -280,12 +281,10 @@ Port::omrfile_stat(const char *path, unsigned int flags, struct J9FileStat *buf)
}

result = GetFileAttributesW(unicodePath);
if (unicodeBuffer != unicodePath) {
Port::omrmem_free((void **)&unicodePath);
}

if (INVALID_FILE_ATTRIBUTES == result) {
return RC_FAILED;
rc = RC_FAILED;
goto cleanup;
}

if (result & FILE_ATTRIBUTE_DIRECTORY) {
Expand Down Expand Up @@ -314,7 +313,8 @@ Port::omrfile_stat(const char *path, unsigned int flags, struct J9FileStat *buf)

result = GetFullPathNameW(unicodePath, UNICODE_BUFFER_SIZE, driveBuffer, NULL);
if (result == 0 || result > UNICODE_BUFFER_SIZE) {
return RC_FAILED;
rc = RC_FAILED;
goto cleanup;
}
driveBuffer[3] = '\0'; /* Chop off everything after the initial X:\ */
switch (GetDriveTypeW(driveBuffer)) {
Expand All @@ -330,7 +330,12 @@ Port::omrfile_stat(const char *path, unsigned int flags, struct J9FileStat *buf)
}
}

return RC_OK;
cleanup:
if (unicodeBuffer != unicodePath) {
Port::omrmem_free((void **)&unicodePath);
}

return rc;
}

RCType
Expand Down