File tree Expand file tree Collapse file tree 1 file changed +8
-3
lines changed
Source/NETworkManager.Models/Firewall Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -42,9 +42,9 @@ private bool ApplyRules(List<FirewallRule> rules)
4242 string nextRule = string . Empty ;
4343 try
4444 {
45- nextRule += $ "New-NetFirewallRule -DisplayName '{ rule . Name } '";
45+ nextRule += $ "New-NetFirewallRule -DisplayName '{ SanitizeStringArguments ( rule . Name ) } '";
4646 if ( ! string . IsNullOrEmpty ( rule . Description ) )
47- nextRule += $ " -Description '{ rule . Description } '";
47+ nextRule += $ " -Description '{ SanitizeStringArguments ( rule . Description ) } '";
4848 nextRule += $ " -Direction { Enum . GetName ( rule . Direction ) } ";
4949 if ( rule . LocalPorts . Count > 0
5050 && rule . Protocol is FirewallProtocol . TCP or FirewallProtocol . UDP )
@@ -64,7 +64,7 @@ private bool ApplyRules(List<FirewallRule> rules)
6464 try
6565 {
6666 if ( File . Exists ( rule . Program . Name ) )
67- nextRule += $ " -Program '{ rule . Program . Name } '";
67+ nextRule += $ " -Program '{ SanitizeStringArguments ( rule . Program . Name ) } '";
6868 else
6969 continue ;
7070 }
@@ -125,6 +125,11 @@ private static string GetClearAllRulesCommand()
125125 {
126126 return $ "Remove-NetFirewallRule -DisplayName 'NwM_*'";
127127 }
128+
129+ private static string SanitizeStringArguments ( string value )
130+ {
131+ return value . Replace ( "'" , "''" ) ;
132+ }
128133
129134 /// <summary>
130135 /// Applies firewall rules asynchronously by invoking the ApplyRules method in a separate task.
You can’t perform that action at this time.
0 commit comments