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

Side by Side Diff: remoting/protocol/network_settings.cc

Issue 966433002: Malformed PortRange or ThirdPartyAuthConfig trigger OnPolicyError. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months 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
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "remoting/protocol/network_settings.h"
6
7 #include <limits.h>
8 #include <stdlib.h>
9
10 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/string_util.h"
12
13 namespace remoting {
14 namespace protocol {
15
16 // static
17 bool NetworkSettings::ParsePortRange(const std::string& port_range,
18 uint16* out_min_port,
19 uint16* out_max_port) {
20 size_t separator_index = port_range.find('-');
21 if (separator_index == std::string::npos)
22 return false;
23
24 std::string min_port_string, max_port_string;
25 base::TrimWhitespaceASCII(port_range.substr(0, separator_index),
26 base::TRIM_ALL,
27 &min_port_string);
28 base::TrimWhitespaceASCII(port_range.substr(separator_index + 1),
29 base::TRIM_ALL,
30 &max_port_string);
31
32 unsigned min_port, max_port;
33 if (!base::StringToUint(min_port_string, &min_port) ||
34 !base::StringToUint(max_port_string, &max_port)) {
35 return false;
36 }
37
38 if (min_port == 0 || min_port > max_port || max_port > USHRT_MAX)
39 return false;
40
41 *out_min_port = static_cast<uint16>(min_port);
42 *out_max_port = static_cast<uint16>(max_port);
43 return true;
44 }
45
46 } // namespace protocol
47 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698