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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/proxy/dhcp_proxy_script_adapter_fetcher_win.h" 5 #include "net/proxy/dhcp_proxy_script_adapter_fetcher_win.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop_proxy.h" 8 #include "base/message_loop_proxy.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/sys_string_conversions.h" 10 #include "base/sys_string_conversions.h"
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 send_params, request_params, 258 send_params, request_params,
259 result_buffer.get(), &result_buffer_size, 259 result_buffer.get(), &result_buffer_size,
260 NULL); 260 NULL);
261 ++retry_count; 261 ++retry_count;
262 } while (res == ERROR_MORE_DATA && retry_count <= 3); 262 } while (res == ERROR_MORE_DATA && retry_count <= 3);
263 263
264 if (res != NO_ERROR) { 264 if (res != NO_ERROR) {
265 LOG(INFO) << "Error fetching PAC URL from DHCP: " << res; 265 LOG(INFO) << "Error fetching PAC URL from DHCP: " << res;
266 UMA_HISTOGRAM_COUNTS("Net.DhcpWpadUnhandledDhcpError", 1); 266 UMA_HISTOGRAM_COUNTS("Net.DhcpWpadUnhandledDhcpError", 1);
267 } else if (wpad_params.nBytesData) { 267 } else if (wpad_params.nBytesData) {
268 // The result should be ASCII, not wide character. 268 #ifndef NDEBUG
269 DCHECK_EQ(strlen(reinterpret_cast<const char*>(wpad_params.Data)) + 1, 269 // The result should be ASCII, not wide character. Some DHCP
270 wpad_params.nBytesData); 270 // servers appear to count the trailing NULL in nBytesData, others
271 // Return only up to the first null in case of embedded NULLs; if the 271 // do not.
272 // server is giving us back a buffer with embedded NULLs, something is 272 size_t count_without_null =
273 // broken anyway. 273 strlen(reinterpret_cast<const char*>(wpad_params.Data));
274 return std::string(reinterpret_cast<const char *>(wpad_params.Data)); 274 DCHECK(count_without_null == wpad_params.nBytesData ||
275 count_without_null + 1 == wpad_params.nBytesData);
276 #endif
277 // Belt and suspenders: First, ensure we NULL-terminate after
278 // nBytesData; this is the inner constructor with nBytesData as a
279 // parameter. Then, return only up to the first null in case of
280 // embedded NULLs; this is the outer constructor that takes the
281 // result of c_str() on the inner. If the server is giving us
282 // back a buffer with embedded NULLs, something is broken anyway.
283 return std::string(
284 std::string(reinterpret_cast<const char *>(wpad_params.Data),
285 wpad_params.nBytesData).c_str());
eroman 2011/12/12 20:52:53 clever approach!
275 } 286 }
276 287
277 return ""; 288 return "";
278 } 289 }
279 290
280 } // namespace net 291 } // namespace net
OLDNEW
« 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