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

Side by Side Diff: net/proxy/proxy_config_service_linux.cc

Issue 2968573002: Check the return value of base::StringToInt() in (Closed)
Patch Set: Created 3 years, 5 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/proxy/proxy_config_service_linux.h" 5 #include "net/proxy/proxy_config_service_linux.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #if defined(USE_GCONF) 8 #if defined(USE_GCONF)
9 #include <gconf/gconf-client.h> 9 #include <gconf/gconf-client.h>
10 #endif // defined(USE_GCONF) 10 #endif // defined(USE_GCONF)
(...skipping 838 matching lines...) Expand 10 before | Expand all | Expand 10 after
849 VLOG(1) << "Found gnome-network-properties. Will fall back to gconf."; 849 VLOG(1) << "Found gnome-network-properties. Will fall back to gconf.";
850 return false; 850 return false;
851 } 851 }
852 } 852 }
853 853
854 VLOG(1) << "All gsettings tests OK. Will get proxy config from gsettings."; 854 VLOG(1) << "All gsettings tests OK. Will get proxy config from gsettings.";
855 return true; 855 return true;
856 } 856 }
857 #endif // defined(USE_GIO) 857 #endif // defined(USE_GIO)
858 858
859 // Converts |value| from a decimal string to an int. If there was a failure
860 // parsing, returns |default_value|.
861 int StringToIntOrDefault(base::StringPiece value, int default_value) {
862 int result;
863 if (base::StringToInt(value, &result))
864 return result;
865 return default_value;
866 }
867
859 // This is the KDE version that reads kioslaverc and simulates gconf. 868 // This is the KDE version that reads kioslaverc and simulates gconf.
860 // Doing this allows the main Delegate code, as well as the unit tests 869 // Doing this allows the main Delegate code, as well as the unit tests
861 // for it, to stay the same - and the settings map fairly well besides. 870 // for it, to stay the same - and the settings map fairly well besides.
862 class SettingGetterImplKDE : public ProxyConfigServiceLinux::SettingGetter { 871 class SettingGetterImplKDE : public ProxyConfigServiceLinux::SettingGetter {
863 public: 872 public:
864 explicit SettingGetterImplKDE(base::Environment* env_var_getter) 873 explicit SettingGetterImplKDE(base::Environment* env_var_getter)
865 : inotify_fd_(-1), 874 : inotify_fd_(-1),
866 notify_delegate_(nullptr), 875 notify_delegate_(nullptr),
867 debounce_timer_(new base::OneShotTimer()), 876 debounce_timer_(new base::OneShotTimer()),
868 indirect_manual_(false), 877 indirect_manual_(false),
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
1081 tokens.push_back(token); 1090 tokens.push_back(token);
1082 } 1091 }
1083 strings_table_[key] = tokens; 1092 strings_table_[key] = tokens;
1084 } 1093 }
1085 1094
1086 void AddKDESetting(const std::string& key, const std::string& value) { 1095 void AddKDESetting(const std::string& key, const std::string& value) {
1087 if (key == "ProxyType") { 1096 if (key == "ProxyType") {
1088 const char* mode = "none"; 1097 const char* mode = "none";
1089 indirect_manual_ = false; 1098 indirect_manual_ = false;
1090 auto_no_pac_ = false; 1099 auto_no_pac_ = false;
1091 int int_value; 1100 int int_value = StringToIntOrDefault(value, 0);
1092 base::StringToInt(value, &int_value);
1093 switch (int_value) { 1101 switch (int_value) {
1094 case 0: // No proxy, or maybe kioslaverc syntax error.
1095 break;
1096 case 1: // Manual configuration. 1102 case 1: // Manual configuration.
1097 mode = "manual"; 1103 mode = "manual";
1098 break; 1104 break;
1099 case 2: // PAC URL. 1105 case 2: // PAC URL.
1100 mode = "auto"; 1106 mode = "auto";
1101 break; 1107 break;
1102 case 3: // WPAD. 1108 case 3: // WPAD.
1103 mode = "auto"; 1109 mode = "auto";
1104 auto_no_pac_ = true; 1110 auto_no_pac_ = true;
1105 break; 1111 break;
1106 case 4: // Indirect manual via environment variables. 1112 case 4: // Indirect manual via environment variables.
1107 mode = "manual"; 1113 mode = "manual";
1108 indirect_manual_ = true; 1114 indirect_manual_ = true;
1109 break; 1115 break;
1116 default: // No proxy, or maybe kioslaverc syntax error.
eroman 2017/06/29 21:11:18 (Previously didn't account for negative numbers)
1117 break;
1110 } 1118 }
1111 string_table_[PROXY_MODE] = mode; 1119 string_table_[PROXY_MODE] = mode;
1112 } else if (key == "Proxy Config Script") { 1120 } else if (key == "Proxy Config Script") {
1113 string_table_[PROXY_AUTOCONF_URL] = value; 1121 string_table_[PROXY_AUTOCONF_URL] = value;
1114 } else if (key == "httpProxy") { 1122 } else if (key == "httpProxy") {
1115 AddProxy(PROXY_HTTP_HOST, value); 1123 AddProxy(PROXY_HTTP_HOST, value);
1116 } else if (key == "httpsProxy") { 1124 } else if (key == "httpsProxy") {
1117 AddProxy(PROXY_HTTPS_HOST, value); 1125 AddProxy(PROXY_HTTPS_HOST, value);
1118 } else if (key == "ftpProxy") { 1126 } else if (key == "ftpProxy") {
1119 AddProxy(PROXY_FTP_HOST, value); 1127 AddProxy(PROXY_FTP_HOST, value);
1120 } else if (key == "socksProxy") { 1128 } else if (key == "socksProxy") {
1121 // Older versions of KDE configure SOCKS in a weird way involving 1129 // Older versions of KDE configure SOCKS in a weird way involving
1122 // LD_PRELOAD and a library that intercepts network calls to SOCKSify 1130 // LD_PRELOAD and a library that intercepts network calls to SOCKSify
1123 // them. We don't support it. KDE 4.8 added a proper SOCKS setting. 1131 // them. We don't support it. KDE 4.8 added a proper SOCKS setting.
1124 AddProxy(PROXY_SOCKS_HOST, value); 1132 AddProxy(PROXY_SOCKS_HOST, value);
1125 } else if (key == "ReversedException") { 1133 } else if (key == "ReversedException") {
1126 // We count "true" or any nonzero number as true, otherwise false. 1134 // We count "true" or any nonzero number as true, otherwise false.
1127 // Note that if the value is not actually numeric StringToInt() 1135 // A failure parsing the integer will interpret it as 0 (false).
1128 // will return 0, which we count as false. 1136 int int_value = StringToIntOrDefault(value, 0);
1129 int int_value;
1130 base::StringToInt(value, &int_value);
1131 reversed_bypass_list_ = (value == "true" || int_value); 1137 reversed_bypass_list_ = (value == "true" || int_value);
eroman 2017/06/29 21:11:18 (Some of this parsing is weird... but I am just tr
mmenke 2017/06/29 22:21:20 Could you are least change this to: reversed_bypa
eroman 2017/06/29 22:33:58 Done.
1132 } else if (key == "NoProxyFor") { 1138 } else if (key == "NoProxyFor") {
1133 AddHostList(PROXY_IGNORE_HOSTS, value); 1139 AddHostList(PROXY_IGNORE_HOSTS, value);
1134 } else if (key == "AuthMode") { 1140 } else if (key == "AuthMode") {
1135 // Check for authentication, just so we can warn. 1141 // Check for authentication, just so we can warn.
1136 int mode; 1142 int mode = StringToIntOrDefault(value, 0);
1137 base::StringToInt(value, &mode);
1138 if (mode) { 1143 if (mode) {
1139 // ProxyConfig does not support authentication parameters, but 1144 // ProxyConfig does not support authentication parameters, but
1140 // Chrome will prompt for the password later. So we ignore this. 1145 // Chrome will prompt for the password later. So we ignore this.
1141 LOG(WARNING) << 1146 LOG(WARNING) <<
1142 "Proxy authentication parameters ignored, see bug 16709"; 1147 "Proxy authentication parameters ignored, see bug 16709";
1143 } 1148 }
1144 } 1149 }
1145 } 1150 }
1146 1151
1147 void ResolveIndirect(StringSetting key) { 1152 void ResolveIndirect(StringSetting key) {
(...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after
1773 void ProxyConfigServiceLinux::RemoveObserver(Observer* observer) { 1778 void ProxyConfigServiceLinux::RemoveObserver(Observer* observer) {
1774 delegate_->RemoveObserver(observer); 1779 delegate_->RemoveObserver(observer);
1775 } 1780 }
1776 1781
1777 ProxyConfigService::ConfigAvailability 1782 ProxyConfigService::ConfigAvailability
1778 ProxyConfigServiceLinux::GetLatestProxyConfig(ProxyConfig* config) { 1783 ProxyConfigServiceLinux::GetLatestProxyConfig(ProxyConfig* config) {
1779 return delegate_->GetLatestProxyConfig(config); 1784 return delegate_->GetLatestProxyConfig(config);
1780 } 1785 }
1781 1786
1782 } // namespace net 1787 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/proxy/proxy_config_service_linux_unittest.cc » ('j') | net/proxy/proxy_config_service_linux_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698