dawn::wire::client::Adapter: Deep-copy string from the AdapterInfo
Otherwise AdapterInfo might be pointing at garbage data that's not
null-terminated.
Fixed: 369239987
Change-Id: I821af26cf0ee3240760b99f7e3c51dfcd55dfa94
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/207954
Reviewed-by: James Price <jrprice@google.com>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Jiawei Shao <jiawei.shao@intel.com>
diff --git a/src/dawn/wire/client/Adapter.cpp b/src/dawn/wire/client/Adapter.cpp
index 02b2fda..9503051 100644
--- a/src/dawn/wire/client/Adapter.cpp
+++ b/src/dawn/wire/client/Adapter.cpp
@@ -163,6 +163,17 @@
void Adapter::SetInfo(const WGPUAdapterInfo* info) {
mInfo = *info;
+
+ // Deep copy the string pointed out by info.
+ mVendor = info->vendor;
+ mInfo.vendor = mVendor.c_str();
+ mArchitecture = info->architecture;
+ mInfo.architecture = mArchitecture.c_str();
+ mDeviceName = info->device;
+ mInfo.device = mDeviceName.c_str();
+ mDescription = info->description;
+ mInfo.description = mDescription.c_str();
+
mInfo.nextInChain = nullptr;
// Loop through the chained struct.
diff --git a/src/dawn/wire/client/Adapter.h b/src/dawn/wire/client/Adapter.h
index 34b903a..743598a 100644
--- a/src/dawn/wire/client/Adapter.h
+++ b/src/dawn/wire/client/Adapter.h
@@ -28,6 +28,7 @@
#ifndef SRC_DAWN_WIRE_CLIENT_ADAPTER_H_
#define SRC_DAWN_WIRE_CLIENT_ADAPTER_H_
+#include <string>
#include <vector>
#include "dawn/wire/WireClient.h"
@@ -68,6 +69,10 @@
private:
LimitsAndFeatures mLimitsAndFeatures;
WGPUAdapterInfo mInfo;
+ std::string mVendor;
+ std::string mArchitecture;
+ std::string mDeviceName;
+ std::string mDescription;
std::vector<WGPUMemoryHeapInfo> mMemoryHeapInfo;
WGPUAdapterPropertiesD3D mD3DProperties;
WGPUAdapterPropertiesVk mVkProperties;