Commit fe4061f8 authored by joi@chromium.org's avatar joi@chromium.org

Add range check to allow for NULL to be counted as data or not by DHCP server.

BUG=106851
TEST=On Windows, fire up Chrome and navigate to a couple of web pages, with proxy settings set to auto-detect.


Review URL: http://codereview.chromium.org/8892004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@114019 0039d316-1c4b-4281-b951-d872f2087c98
parent 30e6b180
...@@ -265,13 +265,24 @@ std::string DhcpProxyScriptAdapterFetcher::GetPacURLFromDhcp( ...@@ -265,13 +265,24 @@ std::string DhcpProxyScriptAdapterFetcher::GetPacURLFromDhcp(
LOG(INFO) << "Error fetching PAC URL from DHCP: " << res; LOG(INFO) << "Error fetching PAC URL from DHCP: " << res;
UMA_HISTOGRAM_COUNTS("Net.DhcpWpadUnhandledDhcpError", 1); UMA_HISTOGRAM_COUNTS("Net.DhcpWpadUnhandledDhcpError", 1);
} else if (wpad_params.nBytesData) { } else if (wpad_params.nBytesData) {
// The result should be ASCII, not wide character. #ifndef NDEBUG
DCHECK_EQ(strlen(reinterpret_cast<const char*>(wpad_params.Data)) + 1, // The result should be ASCII, not wide character. Some DHCP
wpad_params.nBytesData); // servers appear to count the trailing NULL in nBytesData, others
// Return only up to the first null in case of embedded NULLs; if the // do not.
// server is giving us back a buffer with embedded NULLs, something is size_t count_without_null =
// broken anyway. strlen(reinterpret_cast<const char*>(wpad_params.Data));
return std::string(reinterpret_cast<const char *>(wpad_params.Data)); DCHECK(count_without_null == wpad_params.nBytesData ||
count_without_null + 1 == wpad_params.nBytesData);
#endif
// Belt and suspenders: First, ensure we NULL-terminate after
// nBytesData; this is the inner constructor with nBytesData as a
// parameter. Then, return only up to the first null in case of
// embedded NULLs; this is the outer constructor that takes the
// result of c_str() on the inner. If the server is giving us
// back a buffer with embedded NULLs, something is broken anyway.
return std::string(
std::string(reinterpret_cast<const char *>(wpad_params.Data),
wpad_params.nBytesData).c_str());
} }
return ""; return "";
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment