summaryrefslogtreecommitdiff
path: root/base
diff options
context:
space:
mode:
authorDoug Horn <doughorn@google.com>2021-01-07 12:36:04 -0800
committerDoug Horn <doughorn@google.com>2021-01-07 12:36:07 -0800
commitd7b578731645aa338970c24110337561a1ca58ce (patch)
tree193f50d94db61f7d7db2f7cd1f8bb29c6e5161cb /base
parent36fa8a7f89f6e89bf00313f18f1290059284fc54 (diff)
downloadvulkan-cereal-d7b578731645aa338970c24110337561a1ca58ce.tar.gz
[Win] Properly parse all valid Win32 file urls.
We now make sure we properly parse all file:// urls properly for the windows platform. Includes a unit test to validate parsing. This is a manual cherry-pick of aosp/1483306. Change-Id: I80d16ee1ed77db3c6024635f16ddc6ae12106020
Diffstat (limited to 'base')
-rw-r--r--base/SharedMemory_posix.cpp5
-rw-r--r--base/SharedMemory_unittest.cpp4
-rw-r--r--base/SharedMemory_win32.cpp11
3 files changed, 16 insertions, 4 deletions
diff --git a/base/SharedMemory_posix.cpp b/base/SharedMemory_posix.cpp
index 5198a6df..7bb91c8e 100644
--- a/base/SharedMemory_posix.cpp
+++ b/base/SharedMemory_posix.cpp
@@ -91,6 +91,11 @@ int SharedMemory::openInternal(int oflag, int mode, bool doMapping) {
mFd = shm_open(mName.c_str(), oflag, mode);
} else {
mFd = ::open(mName.c_str(), oflag, mode);
+ // Make sure the file can hold at least mSize bytes..
+ struct stat stat;
+ if (!fstat(mFd, &stat) && stat.st_size < mSize) {
+ ftruncate(mFd, mSize);
+ }
}
if (mFd == -1) {
err = -errno;
diff --git a/base/SharedMemory_unittest.cpp b/base/SharedMemory_unittest.cpp
index 23bc50ed..a1c29fd9 100644
--- a/base/SharedMemory_unittest.cpp
+++ b/base/SharedMemory_unittest.cpp
@@ -58,8 +58,8 @@ TEST(SharedMemory, ShareVisibileWithinSameProc) {
// ts.getTempRoot()->path(), "shāred.mem");
// const mode_t user_read_only = 0600;
// std::string message = "Hello World!";
-// base::SharedMemory mWriter("file://" + unique_name, message.size());
-// base::SharedMemory mReader("file://" + unique_name, message.size());
+// base::SharedMemory mWriter("file:///" + unique_name, message.size());
+// base::SharedMemory mReader("file:///" + unique_name, message.size());
//
// ASSERT_FALSE(mWriter.isOpen());
// ASSERT_FALSE(mReader.isOpen());
diff --git a/base/SharedMemory_win32.cpp b/base/SharedMemory_win32.cpp
index 6b253f10..b6214ddd 100644
--- a/base/SharedMemory_win32.cpp
+++ b/base/SharedMemory_win32.cpp
@@ -13,6 +13,7 @@
// limitations under the License.
#include "base/SharedMemory.h"
+#include <shlwapi.h>
#include <cassert>
#include <string>
@@ -25,9 +26,15 @@ namespace base {
SharedMemory::SharedMemory(const std::string& name, size_t size) : mSize(size) {
const std::string kFileUri = "file://";
if (name.find(kFileUri, 0) == 0) {
+ // Convert URI to path using win32 api.
+ const Win32UnicodeString srcUri(name);
+ WCHAR path[MAX_PATH];
+ DWORD cPath = MAX_PATH;
+ auto HR = PathCreateFromUrlW(srcUri.c_str(), path, &cPath, NULL);
+ assert(HR == S_OK);
+ const Win32UnicodeString destPath(path);
+ mName = PathUtils::recompose(PathUtils::decompose(destPath.toString()));
mShareType = ShareType::FILE_BACKED;
- auto path = name.substr(kFileUri.size());
- mName = PathUtils::recompose(PathUtils::decompose(path));
} else {
mShareType = ShareType::SHARED_MEMORY;
mName = "SHM_" + name;