Skip to content

Commit 2d06248

Browse files
authored
Make scripts execution safer (gitextensions#8182)
* Scripts may not have arguments, pass "" in this case instead of null. * Scripts may fail during execution, show an error message instead of crashing the process.
1 parent c30cdf5 commit 2d06248

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

GitUI/CommandsDialogs/FormBrowse.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -997,9 +997,18 @@ void LoadUserMenu()
997997

998998
button.Click += delegate
999999
{
1000-
if (ScriptRunner.RunScript(this, Module, script.Name, UICommands, RevisionGrid).NeedsGridRefresh)
1000+
try
10011001
{
1002-
RevisionGrid.RefreshRevisions();
1002+
if (ScriptRunner.RunScript(this, Module, script.Name, UICommands, RevisionGrid).NeedsGridRefresh)
1003+
{
1004+
RevisionGrid.RefreshRevisions();
1005+
}
1006+
}
1007+
catch (Exception ex)
1008+
{
1009+
MessageBox.Show(this,
1010+
$"Failed to execute '{script.Name}' script.{Environment.NewLine}Reason: {ex.Message}",
1011+
Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
10031012
}
10041013
};
10051014

GitUI/Script/ScriptRunner.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,10 @@ private static CommandStatus RunScript(IWin32Window owner, IGitModule module, Sc
152152
}
153153
else
154154
{
155-
new Executable(command, module.WorkingDir).Start(argument);
155+
// It is totally valid to have a command without an argument, e.g.:
156+
// Command : myscript.cmd
157+
// Arguments: <blank>
158+
new Executable(command, module.WorkingDir).Start(argument ?? string.Empty);
156159
}
157160
}
158161

0 commit comments

Comments
 (0)