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

Windows: recover from buffer overflow errors in smartblockdns #1031

Merged
merged 4 commits into from
May 20, 2021
Merged
Show file tree
Hide file tree
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
Binary file modified tools/smartdnsblock/bin/smartdnsblock.exe
Binary file not shown.
27 changes: 23 additions & 4 deletions tools/smartdnsblock/smartdnsblock/smartdnsblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,34 @@ ULONG GET_ADAPTERS_ADDRESSES_BUFFER_SIZE = 16384;
PCWSTR FILTER_PROVIDER_NAME = L"Outline";
PCWSTR SUBLAYER_NAME = L"Smart DNS Block";

UINT64 MAX_TRIES = 2;
UINT64 LOWER_FILTER_WEIGHT = 10;
UINT64 HIGHER_FILTER_WEIGHT = 20;

int main(int argc, char **argv) {
// Lookup the interface index of outline-tap0.
PIP_ADAPTER_ADDRESSES adaptersAddresses =
(IP_ADAPTER_ADDRESSES *)malloc(GET_ADAPTERS_ADDRESSES_BUFFER_SIZE);
DWORD result = GetAdaptersAddresses(AF_INET, 0, NULL, adaptersAddresses,
&GET_ADAPTERS_ADDRESSES_BUFFER_SIZE);
PIP_ADAPTER_ADDRESSES adaptersAddresses = NULL;

UINT64 count = 0;
DWORD result = 0;
do {
adaptersAddresses = (IP_ADAPTER_ADDRESSES*)malloc(GET_ADAPTERS_ADDRESSES_BUFFER_SIZE);
alalamav marked this conversation as resolved.
Show resolved Hide resolved

// Required value will be told to GET_ADAPTERS_ADDRESSES_BUFFER_SIZE
// if GetAdaptersAddresses() returns ERROR_BUFFER_OVERFLOW:
// https://docs.microsoft.com/en-us/windows/win32/api/iphlpapi/nf-iphlpapi-getadaptersaddresses#return-value
result = GetAdaptersAddresses(AF_INET, 0, NULL, adaptersAddresses,
&GET_ADAPTERS_ADDRESSES_BUFFER_SIZE);

if (result != NO_ERROR) {
wcerr << "could not fetch network device list: " << result << endl;
free(adaptersAddresses);
adaptersAddresses = NULL;
} else {
wcout << "fetch network device list success!";
}
} while ((result == ERROR_BUFFER_OVERFLOW) && (count++ < MAX_TRIES));

if (result != NO_ERROR) {
wcerr << "could not fetch network device list: " << result << endl;
return 1;
Expand Down