Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(467)

Unified Diff: net/proxy/dhcp_proxy_script_adapter_fetcher_win.cc

Issue 8892004: Add range check to allow for NULL to be counted as data or not by DHCP server. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Belt and suspenders. Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/proxy/dhcp_proxy_script_adapter_fetcher_win.cc
diff --git a/net/proxy/dhcp_proxy_script_adapter_fetcher_win.cc b/net/proxy/dhcp_proxy_script_adapter_fetcher_win.cc
index 32baeb7a634dbd85a67efaaf7de4a74b912dcadc..5a24c63e509ce62e668ef9a3b83159b331c0096e 100644
--- a/net/proxy/dhcp_proxy_script_adapter_fetcher_win.cc
+++ b/net/proxy/dhcp_proxy_script_adapter_fetcher_win.cc
@@ -265,13 +265,24 @@ std::string DhcpProxyScriptAdapterFetcher::GetPacURLFromDhcp(
LOG(INFO) << "Error fetching PAC URL from DHCP: " << res;
UMA_HISTOGRAM_COUNTS("Net.DhcpWpadUnhandledDhcpError", 1);
} else if (wpad_params.nBytesData) {
- // The result should be ASCII, not wide character.
- DCHECK_EQ(strlen(reinterpret_cast<const char*>(wpad_params.Data)) + 1,
- wpad_params.nBytesData);
- // Return only up to the first null in case of embedded NULLs; if the
- // server is giving us back a buffer with embedded NULLs, something is
- // broken anyway.
- return std::string(reinterpret_cast<const char *>(wpad_params.Data));
+#ifndef NDEBUG
+ // The result should be ASCII, not wide character. Some DHCP
+ // servers appear to count the trailing NULL in nBytesData, others
+ // do not.
+ size_t count_without_null =
+ strlen(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());
eroman 2011/12/12 20:52:53 clever approach!
}
return "";
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698