summaryrefslogtreecommitdiffstats
path: root/net/http
diff options
context:
space:
mode:
authorericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-23 19:57:43 +0000
committerericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-23 19:57:43 +0000
commit15a5ccf888664e1dadc02fd336d901c14524d81e (patch)
tree11408c29dc90d0409441206d4f4b47ed0264ae7f /net/http
parent2cfe388ab98dcd6771bb9795c673716d4eb62d05 (diff)
downloadchromium_src-15a5ccf888664e1dadc02fd336d901c14524d81e.zip
chromium_src-15a5ccf888664e1dadc02fd336d901c14524d81e.tar.gz
chromium_src-15a5ccf888664e1dadc02fd336d901c14524d81e.tar.bz2
Fix array out of bounds in unit test.
I was passing a non-null-terminated string to a caller that expected null-terminated string. Review URL: http://codereview.chromium.org/7934 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@3845 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http')
-rw-r--r--net/http/http_network_transaction_unittest.cc18
1 files changed, 8 insertions, 10 deletions
diff --git a/net/http/http_network_transaction_unittest.cc b/net/http/http_network_transaction_unittest.cc
index 8568ec9..d5f0228 100644
--- a/net/http/http_network_transaction_unittest.cc
+++ b/net/http/http_network_transaction_unittest.cc
@@ -268,9 +268,8 @@ SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[]) {
return out;
}
-// Create a long header list that consumes >= |size| bytes. The caller is
-// responsible for freeing the memory.
-char* MakeLargeHeadersString(int size) {
+// Fill |str| with a long header list that consumes >= |size| bytes.
+void FillLargeHeadersString(std::string* str, int size) {
const char* row =
"SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n";
const int sizeof_row = strlen(row);
@@ -278,11 +277,10 @@ char* MakeLargeHeadersString(int size) {
ceil(static_cast<float>(size) / sizeof_row));
const int sizeof_data = num_rows * sizeof_row;
DCHECK(sizeof_data >= size);
-
- char* data = new char[sizeof_data];
+ str->reserve(sizeof_data);
+
for (int i = 0; i < num_rows; ++i)
- memcpy(data + i * sizeof_row, row, sizeof_row);
- return data;
+ str->append(row, sizeof_row);
}
//-----------------------------------------------------------------------------
@@ -833,12 +831,12 @@ TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) {
request.load_flags = 0;
// Respond with 50 kb of headers (we should fail after 32 kb).
- scoped_array<char> large_headers_string(MakeLargeHeadersString(
- 50 * 1024));
+ std::string large_headers_string;
+ FillLargeHeadersString(&large_headers_string, 50 * 1024);
MockRead data_reads[] = {
MockRead("HTTP/1.0 200 OK\r\n"),
- MockRead(large_headers_string.get()),
+ MockRead(true, large_headers_string.data(), large_headers_string.size()),
MockRead("\r\nBODY"),
MockRead(false, net::OK),
};