Make sure adapter info/properties tests actually test for UAF
See comments.
Bug: 335383516
Change-Id: I5b7babdcbd014c13612557f7c64a385cfaf5a5a1
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/190563
Reviewed-by: Fr <beaufort.francois@gmail.com>
Commit-Queue: Austin Eng <enga@chromium.org>
Auto-Submit: Kai Ninomiya <kainino@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
diff --git a/src/dawn/tests/end2end/AdapterCreationTests.cpp b/src/dawn/tests/end2end/AdapterCreationTests.cpp
index 3e0a486..066b436 100644
--- a/src/dawn/tests/end2end/AdapterCreationTests.cpp
+++ b/src/dawn/tests/end2end/AdapterCreationTests.cpp
@@ -476,14 +476,22 @@
wgpu::AdapterProperties properties;
adapter.GetProperties(&properties);
- // Release the adapter.
- adapter = nullptr;
-
- // Copy the properties to std::string, this should not be a use-after-free.
+ // Make a copy of the properties.
std::string vendorName = properties.vendorName;
std::string architecture = properties.architecture;
std::string name = properties.name;
std::string driverDescription = properties.driverDescription;
+
+ // Release the adapter.
+ adapter = nullptr;
+
+ // Ensure we still read the properties (pointers are still valid).
+ // Check the values are equal to make sure they haven't been overwritten,
+ // and to make sure the compiler can't elide no-op pointer reads.
+ EXPECT_EQ(properties.vendorName, vendorName);
+ EXPECT_EQ(properties.architecture, architecture);
+ EXPECT_EQ(properties.name, name);
+ EXPECT_EQ(properties.driverDescription, driverDescription);
}
// Test that calling AdapterGetInfo returns separate allocations for strings.
@@ -645,7 +653,7 @@
wgpu::AdapterInfo info;
adapter.GetInfo(&info);
- // Copy the info to std::string, this should not be a use-after-free.
+ // Make a copy of the info.
std::string vendor = info.vendor;
std::string architecture = info.architecture;
std::string device = info.device;
@@ -653,6 +661,14 @@
// Release the adapter.
adapter = nullptr;
+
+ // Ensure we still read the info (pointers are still valid).
+ // Check the values are equal to make sure they haven't been overwritten,
+ // and to make sure the compiler can't elide no-op pointer reads.
+ EXPECT_EQ(info.vendor, vendor);
+ EXPECT_EQ(info.architecture, architecture);
+ EXPECT_EQ(info.device, device);
+ EXPECT_EQ(info.description, description);
}
} // anonymous namespace