OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 // Derived from: | 5 // Derived from: |
6 // mozilla/netwerk/protocol/http/src/nsHttpChunkedDecoder.cpp | 6 // mozilla/netwerk/protocol/http/src/nsHttpChunkedDecoder.cpp |
7 // The license block is: | 7 // The license block is: |
8 /* ***** BEGIN LICENSE BLOCK ***** | 8 /* ***** BEGIN LICENSE BLOCK ***** |
9 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 | 9 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
10 * | 10 * |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 // Us: ^\X+[ ]*$ | 180 // Us: ^\X+[ ]*$ |
181 bool HttpChunkedDecoder::ParseChunkSize(const char* start, int len, int* out) { | 181 bool HttpChunkedDecoder::ParseChunkSize(const char* start, int len, int* out) { |
182 DCHECK(len >= 0); | 182 DCHECK(len >= 0); |
183 | 183 |
184 // Strip trailing spaces | 184 // Strip trailing spaces |
185 while (len && start[len - 1] == ' ') | 185 while (len && start[len - 1] == ' ') |
186 len--; | 186 len--; |
187 | 187 |
188 // Be more restrictive than HexStringToInt; | 188 // Be more restrictive than HexStringToInt; |
189 // don't allow inputs with leading "-", "+", "0x", "0X" | 189 // don't allow inputs with leading "-", "+", "0x", "0X" |
190 if (base::StringPiece(start, len).find_first_not_of("0123456789abcdefABCDEF") | 190 base::StringPiece chunk_size(start, len); |
191 != base::StringPiece::npos) | 191 if (chunk_size.find_first_not_of("0123456789abcdefABCDEF") |
| 192 != base::StringPiece::npos) { |
192 return false; | 193 return false; |
| 194 } |
193 | 195 |
194 int parsed_number; | 196 int parsed_number; |
195 bool ok = base::HexStringToInt(start, start + len, &parsed_number); | 197 bool ok = base::HexStringToInt(chunk_size, &parsed_number); |
196 if (ok && parsed_number >= 0) { | 198 if (ok && parsed_number >= 0) { |
197 *out = parsed_number; | 199 *out = parsed_number; |
198 return true; | 200 return true; |
199 } | 201 } |
200 return false; | 202 return false; |
201 } | 203 } |
202 | 204 |
203 } // namespace net | 205 } // namespace net |
OLD | NEW |