aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Duong <joshuaduong@google.com>2022-02-11 10:57:07 -0800
committerJoshua Duong <joshuaduong@google.com>2022-02-11 20:55:51 +0000
commit95e21bc268e0f3bb4b51baea882393c639d945ef (patch)
tree8aaaeb612b6c3a1e3fb9647f0da35e8cf285a502
parente9172c38c10a012f2d8db5c28bd283fc4038908c (diff)
downloadopenscreen-95e21bc268e0f3bb4b51baea882393c639d945ef.tar.gz
[windows] Fix stale pointer dereference.
Bug: 217251994 Test: Manually reduced initial buffer size to execute resize code path. > set ADB_MDNS_OPENSCREEN=1& adb.exe track-devices Change-Id: Ice9416f7237364ebc6dd756b140990992d2189e5
-rw-r--r--platform/impl/network_interface_win.cc5
1 files changed, 2 insertions, 3 deletions
diff --git a/platform/impl/network_interface_win.cc b/platform/impl/network_interface_win.cc
index f90d35d2..c3095457 100644
--- a/platform/impl/network_interface_win.cc
+++ b/platform/impl/network_interface_win.cc
@@ -16,7 +16,6 @@ std::vector<InterfaceInfo> GetAllInterfaces() {
constexpr size_t INITIAL_BUFFER_SIZE = 15000;
ULONG outbuflen = INITIAL_BUFFER_SIZE;
std::vector<unsigned char> charbuf(INITIAL_BUFFER_SIZE);
- PIP_ADAPTER_ADDRESSES paddrs = reinterpret_cast<IP_ADAPTER_ADDRESSES*>(charbuf.data());
DWORD ret = NO_ERROR;
constexpr int MAX_RETRIES = 5;
@@ -25,7 +24,7 @@ std::vector<InterfaceInfo> GetAllInterfaces() {
ret = GetAdaptersAddresses(AF_UNSPEC /* get both v4/v6 addrs */,
GAA_FLAG_INCLUDE_PREFIX,
NULL,
- paddrs,
+ reinterpret_cast<IP_ADAPTER_ADDRESSES*>(charbuf.data()),
&outbuflen);
if (ret == ERROR_BUFFER_OVERFLOW) {
charbuf.resize(outbuflen);
@@ -40,7 +39,7 @@ std::vector<InterfaceInfo> GetAllInterfaces() {
}
std::vector<InterfaceInfo> infos;
- auto pcurraddrs = paddrs;
+ auto pcurraddrs = reinterpret_cast<IP_ADAPTER_ADDRESSES*>(charbuf.data());
while (pcurraddrs != nullptr) {
// TODO: return the interfaces
OSP_DVLOG << "\tIfIndex=" << pcurraddrs->IfIndex;