| 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 int result = | 58 int result = |
| 59 parser.SendRequest("GET / HTTP/1.1\r\n", net::HttpRequestHeaders(), | 59 parser.SendRequest("GET / HTTP/1.1\r\n", net::HttpRequestHeaders(), |
| 60 &response_info, callback.callback()); | 60 &response_info, callback.callback()); |
| 61 result = callback.GetResult(result); | 61 result = callback.GetResult(result); |
| 62 if (net::OK != result) | 62 if (net::OK != result) |
| 63 return 0; | 63 return 0; |
| 64 | 64 |
| 65 result = parser.ReadResponseHeaders(callback.callback()); | 65 result = parser.ReadResponseHeaders(callback.callback()); |
| 66 result = callback.GetResult(result); | 66 result = callback.GetResult(result); |
| 67 | 67 |
| 68 while (result > 0) { | 68 if (result < 0) |
| 69 return 0; |
| 70 |
| 71 while (true) { |
| 69 scoped_refptr<net::IOBufferWithSize> io_buffer( | 72 scoped_refptr<net::IOBufferWithSize> io_buffer( |
| 70 new net::IOBufferWithSize(64)); | 73 new net::IOBufferWithSize(64)); |
| 71 result = parser.ReadResponseBody(io_buffer.get(), io_buffer->size(), | 74 result = parser.ReadResponseBody(io_buffer.get(), io_buffer->size(), |
| 72 callback.callback()); | 75 callback.callback()); |
| 73 | 76 |
| 74 // Releasing the pointer to IOBuffer immediately is more likely to lead to a | 77 // Releasing the pointer to IOBuffer immediately is more likely to lead to a |
| 75 // use-after-free. | 78 // use-after-free. |
| 76 io_buffer = nullptr; | 79 io_buffer = nullptr; |
| 77 | 80 if (callback.GetResult(result) <= 0) |
| 78 result = callback.GetResult(result); | 81 break; |
| 79 } | 82 } |
| 80 | 83 |
| 81 return 0; | 84 return 0; |
| 82 } | 85 } |
| OLD | NEW |