Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(194)

Side by Side Diff: chrome/browser/media/cast_remoting_connector_messaging.cc

Issue 2567263002: Fix Media Remoting Connector stream ID message parsing. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "chrome/browser/media/cast_remoting_connector_messaging.h" 5 #include "chrome/browser/media/cast_remoting_connector_messaging.h"
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 8
9 #include <limits> 9 #include <limits>
10 10
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 43
44 // static 44 // static
45 int32_t CastRemotingConnectorMessaging::GetStreamIdFromStartedMessage( 45 int32_t CastRemotingConnectorMessaging::GetStreamIdFromStartedMessage(
46 base::StringPiece message, base::StringPiece specifier) { 46 base::StringPiece message, base::StringPiece specifier) {
47 auto start = message.find(specifier); 47 auto start = message.find(specifier);
48 if (start == std::string::npos) 48 if (start == std::string::npos)
49 return -1; 49 return -1;
50 start += specifier.size(); 50 start += specifier.size();
51 if (start + 1 >= message.size()) 51 if (start + 1 >= message.size())
52 return -1; // Must be at least one hex digit following the specifier. 52 return -1; // Must be at least one hex digit following the specifier.
53 const auto length = message.find(kMessageFieldSeparator, start) - start;
53 int parsed_value; 54 int parsed_value;
54 if (!base::HexStringToInt( 55 if (!base::HexStringToInt(message.substr(start, length), &parsed_value) ||
55 message.substr(start, message.find(kMessageFieldSeparator, start)),
56 &parsed_value) ||
57 parsed_value < 0 || 56 parsed_value < 0 ||
58 parsed_value > std::numeric_limits<int32_t>::max()) { 57 parsed_value > std::numeric_limits<int32_t>::max()) {
59 return -1; // Non-hex digits, or outside valid range. 58 return -1; // Non-hex digits, or outside valid range.
60 } 59 }
61 return static_cast<int32_t>(parsed_value); 60 return static_cast<int32_t>(parsed_value);
62 } 61 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698