| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/http/http_stream_parser.h" | 5 #include "net/http/http_stream_parser.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 | 122 |
| 123 net::HttpResponseInfo response_info; | 123 net::HttpResponseInfo response_info; |
| 124 int result = | 124 int result = |
| 125 parser.SendRequest("GET / HTTP/1.1\r\n", net::HttpRequestHeaders(), | 125 parser.SendRequest("GET / HTTP/1.1\r\n", net::HttpRequestHeaders(), |
| 126 &response_info, callback.callback()); | 126 &response_info, callback.callback()); |
| 127 CHECK_EQ(net::OK, callback.GetResult(result)); | 127 CHECK_EQ(net::OK, callback.GetResult(result)); |
| 128 | 128 |
| 129 result = parser.ReadResponseHeaders(callback.callback()); | 129 result = parser.ReadResponseHeaders(callback.callback()); |
| 130 result = callback.GetResult(result); | 130 result = callback.GetResult(result); |
| 131 | 131 |
| 132 if (result != net::OK) | 132 if (result < 0) |
| 133 return 0; | 133 return 0; |
| 134 | 134 |
| 135 while (true) { | 135 while (true) { |
| 136 // 64 exactly matches the maximum amount of data returned by a single | 136 // 64 exactly matches the maximum amount of data returned by a single |
| 137 // MockRead, as created above. | 137 // MockRead, as created above. |
| 138 scoped_refptr<net::IOBufferWithSize> io_buffer( | 138 scoped_refptr<net::IOBufferWithSize> io_buffer( |
| 139 new net::IOBufferWithSize(64)); | 139 new net::IOBufferWithSize(64)); |
| 140 result = parser.ReadResponseBody(io_buffer.get(), io_buffer->size(), | 140 result = parser.ReadResponseBody(io_buffer.get(), io_buffer->size(), |
| 141 callback.callback()); | 141 callback.callback()); |
| 142 | 142 |
| 143 // Releasing the pointer to IOBuffer immediately is more likely to lead to a | 143 // Releasing the pointer to IOBuffer immediately is more likely to lead to a |
| 144 // use-after-free. | 144 // use-after-free. |
| 145 io_buffer = nullptr; | 145 io_buffer = nullptr; |
| 146 | 146 |
| 147 if (callback.GetResult(result) <= 0) | 147 if (callback.GetResult(result) <= 0) |
| 148 break; | 148 break; |
| 149 } | 149 } |
| 150 | 150 |
| 151 return 0; | 151 return 0; |
| 152 } | 152 } |
| OLD | NEW |