summaryrefslogtreecommitdiff
path: root/chromium/net/proxy/dhcp_proxy_script_adapter_fetcher_win.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/net/proxy/dhcp_proxy_script_adapter_fetcher_win.cc')
-rw-r--r--chromium/net/proxy/dhcp_proxy_script_adapter_fetcher_win.cc42
1 files changed, 24 insertions, 18 deletions
diff --git a/chromium/net/proxy/dhcp_proxy_script_adapter_fetcher_win.cc b/chromium/net/proxy/dhcp_proxy_script_adapter_fetcher_win.cc
index 676f6c3a4d6..569e8120782 100644
--- a/chromium/net/proxy/dhcp_proxy_script_adapter_fetcher_win.cc
+++ b/chromium/net/proxy/dhcp_proxy_script_adapter_fetcher_win.cc
@@ -9,6 +9,7 @@
#include "base/logging.h"
#include "base/message_loop/message_loop_proxy.h"
#include "base/metrics/histogram.h"
+#include "base/strings/string_util.h"
#include "base/strings/sys_string_conversions.h"
#include "base/task_runner.h"
#include "base/time/time.h"
@@ -263,27 +264,32 @@ std::string DhcpProxyScriptAdapterFetcher::GetPacURLFromDhcp(
LOG(INFO) << "Error fetching PAC URL from DHCP: " << res;
UMA_HISTOGRAM_COUNTS("Net.DhcpWpadUnhandledDhcpError", 1);
} else if (wpad_params.nBytesData) {
-#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());
+ return SanitizeDhcpApiString(
+ reinterpret_cast<const char*>(wpad_params.Data),
+ wpad_params.nBytesData);
}
return "";
}
+// static
+std::string DhcpProxyScriptAdapterFetcher::SanitizeDhcpApiString(
+ const char* data, size_t count_bytes) {
+ // The result should be ASCII, not wide character. Some DHCP
+ // servers appear to count the trailing NULL in nBytesData, others
+ // do not. A few (we've had one report, http://crbug.com/297810)
+ // do not NULL-terminate but may \n-terminate.
+ //
+ // Belt and suspenders and elastic waistband: 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. Finally, trim trailing whitespace.
+ std::string result(std::string(data, count_bytes).c_str());
+ TrimWhitespaceASCII(result, TRIM_TRAILING, &result);
+ return result;
+}
+
} // namespace net