| OLD | NEW |
| 1 // Copyright (c) 2011 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 * |
| 11 * The contents of this file are subject to the Mozilla Public License Version | 11 * The contents of this file are subject to the Mozilla Public License Version |
| (...skipping 168 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 base::StringPiece chunk_size(start, len); | 190 if (base::StringPiece(start, len).find_first_not_of("0123456789abcdefABCDEF") |
| 191 if (chunk_size.find_first_not_of("0123456789abcdefABCDEF") | 191 != base::StringPiece::npos) |
| 192 != base::StringPiece::npos) { | |
| 193 return false; | 192 return false; |
| 194 } | |
| 195 | 193 |
| 196 int parsed_number; | 194 int parsed_number; |
| 197 bool ok = base::HexStringToInt(chunk_size, &parsed_number); | 195 bool ok = base::HexStringToInt(start, start + len, &parsed_number); |
| 198 if (ok && parsed_number >= 0) { | 196 if (ok && parsed_number >= 0) { |
| 199 *out = parsed_number; | 197 *out = parsed_number; |
| 200 return true; | 198 return true; |
| 201 } | 199 } |
| 202 return false; | 200 return false; |
| 203 } | 201 } |
| 204 | 202 |
| 205 } // namespace net | 203 } // namespace net |
| OLD | NEW |