input validation
This commit is contained in:
@@ -58,8 +58,36 @@ namespace shadowsocks_csharp
|
||||
}
|
||||
}
|
||||
|
||||
private static void checkPort(int port)
|
||||
{
|
||||
if (port <= 0 || port > 65535)
|
||||
{
|
||||
throw new ArgumentException("port out of range");
|
||||
}
|
||||
}
|
||||
|
||||
private static void checkPassword(string password)
|
||||
{
|
||||
if (string.IsNullOrEmpty(password))
|
||||
{
|
||||
throw new ArgumentException("password can not be blank");
|
||||
}
|
||||
}
|
||||
|
||||
private static void checkServer(string server)
|
||||
{
|
||||
if (string.IsNullOrEmpty(server))
|
||||
{
|
||||
throw new ArgumentException("server can not be blank");
|
||||
}
|
||||
}
|
||||
|
||||
public static void Save(Config config)
|
||||
{
|
||||
checkPort(config.local_port);
|
||||
checkPort(config.server_port);
|
||||
checkPassword(config.password);
|
||||
checkServer(config.server);
|
||||
try
|
||||
{
|
||||
using (StreamWriter sw = new StreamWriter(File.Open(@"config.json", FileMode.Create)))
|
||||
|
||||
@@ -93,11 +93,11 @@ namespace shadowsocks_csharp
|
||||
}
|
||||
catch (FormatException)
|
||||
{
|
||||
MessageBox.Show("there is format problem");
|
||||
MessageBox.Show("illegal port number format");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.ToString());
|
||||
MessageBox.Show(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user