mirror of
https://github.com/doublecmd/doublecmd.git
synced 2026-06-21 09:58:13 +00:00
FIX: Don't crash on invalid command line, bug [0000224].
This commit is contained in:
parent
ae1684ee31
commit
65e8602742
9 changed files with 201 additions and 98 deletions
|
|
@ -3658,7 +3658,16 @@ begin
|
|||
Param := ' ' + Param;
|
||||
if StartPath <> '' then
|
||||
mbSetCurrentDir(StartPath);
|
||||
Result:= ExecCmdFork(Format('"%s"%s', [Cmd, Param]));
|
||||
|
||||
try
|
||||
Result:= ExecCmdFork(Format('"%s"%s', [Cmd, Param]));
|
||||
except
|
||||
on e: EInvalidCommandLine do
|
||||
begin
|
||||
MessageDlg(rsMsgInvalidCommandLine, rsMsgInvalidCommandLine + ': ' + e.Message, mtError, [mbOK], 0);
|
||||
Result := False;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
|
@ -4202,10 +4211,18 @@ begin
|
|||
begin
|
||||
if gTermWindow and Assigned(Cons) then
|
||||
Cons.Terminal.Write_pty(sCmd + #13)
|
||||
else if bRunInTerm then
|
||||
ExecCmdFork(sCmd, True, gRunInTerm)
|
||||
else
|
||||
ExecCmdFork(sCmd);
|
||||
begin
|
||||
try
|
||||
if bRunInTerm then
|
||||
ExecCmdFork(sCmd, True, gRunInTerm)
|
||||
else
|
||||
ExecCmdFork(sCmd);
|
||||
except
|
||||
on e: EInvalidCommandLine do
|
||||
MessageDlg(rsMsgInvalidCommandLine, rsMsgInvalidCommandLine + ': ' + e.Message, mtError, [mbOK], 0);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end
|
||||
else
|
||||
|
|
|
|||
|
|
@ -407,7 +407,7 @@ implementation
|
|||
uses
|
||||
Dialogs, LCLProc, Forms, StrUtils, uMasks, fMaskInputDlg,
|
||||
uDebug, uLng, uShowMsg, uFileSystemFileSource, uFileSourceUtil,
|
||||
uDCUtils, uGlobs, uFileViewNotebook, uSearchTemplate;
|
||||
uDCUtils, uGlobs, uFileViewNotebook, uSearchTemplate, uOSUtils;
|
||||
|
||||
const
|
||||
MinimumReloadInterval = 1000; // 1 second
|
||||
|
|
@ -942,6 +942,8 @@ begin
|
|||
try
|
||||
uFileSourceUtil.ChooseFile(Self, FSFile);
|
||||
except
|
||||
on e: EInvalidCommandLine do
|
||||
MessageDlg(rsMsgInvalidCommandLine, rsMsgInvalidCommandLine + ': ' + e.Message, mtError, [mbOK], 0);
|
||||
on e: Exception do
|
||||
MessageDlg('Error', e.Message, mtError, [mbOK], 0);
|
||||
end;
|
||||
|
|
|
|||
|
|
@ -71,6 +71,11 @@ type
|
|||
MappedFile : Pointer;
|
||||
end;
|
||||
|
||||
EInvalidCommandLine = class(Exception);
|
||||
EInvalidQuoting = class(EInvalidCommandLine)
|
||||
constructor Create; reintroduce;
|
||||
end;
|
||||
|
||||
const
|
||||
faInvalidAttributes: TFileAttrs = TFileAttrs(-1);
|
||||
|
||||
|
|
@ -287,7 +292,7 @@ procedure FixDateNamesToUTF8;
|
|||
implementation
|
||||
|
||||
uses
|
||||
FileUtil, uDebug, uDCUtils, uGlobs
|
||||
FileUtil, uDebug, uDCUtils, uGlobs, uLng
|
||||
{$IF DEFINED(MSWINDOWS)}
|
||||
, JwaWinCon, Windows, uNTFSLinks, uMyWindows, JwaWinNetWk, uShlObjAdditional
|
||||
, shlobj
|
||||
|
|
@ -1938,4 +1943,11 @@ begin
|
|||
LongDayNames[i] := SysToUTF8(LongDayNames[i]);
|
||||
end;
|
||||
|
||||
{ EInvalidQuoting }
|
||||
|
||||
constructor EInvalidQuoting.Create;
|
||||
begin
|
||||
inherited Create(rsMsgInvalidQuoting);
|
||||
end;
|
||||
|
||||
end.
|
||||
|
|
|
|||
|
|
@ -185,8 +185,13 @@ begin
|
|||
if SameText(sCmd, sCmdVerbProperties) then
|
||||
ShowFileProperties(FileSource, FFiles);
|
||||
|
||||
if not ProcessExtCommand(sCmd, CurrentPath) then
|
||||
frmMain.ExecCmd(sCmd);
|
||||
try
|
||||
if not ProcessExtCommand(sCmd, CurrentPath) then
|
||||
frmMain.ExecCmd(sCmd);
|
||||
except
|
||||
on e: EInvalidCommandLine do
|
||||
MessageDlg(rsMsgErrorInContextMenuCommand, rsMsgInvalidCommandLine + ': ' + e.Message, mtError, [mbOK], 0);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
|
@ -231,7 +236,12 @@ var
|
|||
ExecCmd: String;
|
||||
begin
|
||||
ExecCmd := (Sender as TMenuItem).Hint;
|
||||
ExecCmdFork(ExecCmd);
|
||||
try
|
||||
ExecCmdFork(ExecCmd);
|
||||
except
|
||||
on e: EInvalidCommandLine do
|
||||
MessageDlg(rsMsgErrorInContextMenuCommand, rsMsgInvalidCommandLine + ': ' + e.Message, mtError, [mbOK], 0);
|
||||
end;
|
||||
end;
|
||||
|
||||
function TShellContextMenu.FillOpenWithSubMenu: Boolean;
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ implementation
|
|||
|
||||
uses
|
||||
LCLProc, Dialogs, uGlobs, uLng, uMyWindows, uShellExecute,
|
||||
fMain, uDCUtils, uFormCommands;
|
||||
fMain, uDCUtils, uFormCommands, uOSUtils;
|
||||
|
||||
const
|
||||
USER_CMD_ID = $1000;
|
||||
|
|
@ -489,8 +489,13 @@ begin
|
|||
Exit;
|
||||
end;
|
||||
*)
|
||||
if not ProcessExtCommand(sCmd, CurrentPath) then
|
||||
frmMain.ExecCmd(sCmd);
|
||||
try
|
||||
if not ProcessExtCommand(sCmd, CurrentPath) then
|
||||
frmMain.ExecCmd(sCmd);
|
||||
except
|
||||
on e: EInvalidCommandLine do
|
||||
MessageDlg(rsMsgErrorInContextMenuCommand, rsMsgInvalidCommandLine + ': ' + e.Message, mtError, [mbOK], 0);
|
||||
end;
|
||||
end;
|
||||
finally
|
||||
bHandled:= True;
|
||||
|
|
|
|||
|
|
@ -1236,7 +1236,7 @@ begin
|
|||
end;
|
||||
end;
|
||||
if QuoteChar <> #0 then
|
||||
raise Exception.Create('Invalid quoting');
|
||||
raise EInvalidQuoting.Create;
|
||||
if CurrentArg <> '' then
|
||||
AddArgument;
|
||||
if (not bSplitArgs) then
|
||||
|
|
@ -1281,6 +1281,8 @@ begin
|
|||
if Pos('"', sCmdLine) = 1 then
|
||||
begin
|
||||
iPos := CharPos('"', sCmdLine, 2);
|
||||
if iPos = 0 then
|
||||
raise EInvalidQuoting.Create;
|
||||
sCmd := Copy(sCmdLine, 2, iPos - 2);
|
||||
sParams := Copy(sCmdLine, iPos + 2, Length(sCmdLine) - iPos + 1)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -118,6 +118,9 @@ resourcestring
|
|||
rsMsgTabRenamePrompt = 'New tab name:';
|
||||
rsMsgErrCreateFileDirectoryExists = 'There already exists a directory named "%s".';
|
||||
rsMsgDeletePartiallyCopied = 'Delete the partially copied file ?';
|
||||
rsMsgInvalidCommandLine = 'Error in command line';
|
||||
rsMsgInvalidQuoting = 'Invalid quoting';
|
||||
rsMsgErrorInContextMenuCommand = 'Error in context menu command';
|
||||
|
||||
// for context menu
|
||||
rsMnuActions = 'Actions';
|
||||
|
|
@ -257,6 +260,11 @@ resourcestring
|
|||
rsToolViewer = 'Viewer';
|
||||
rsToolEditor = 'Editor';
|
||||
rsToolDiffer = 'Differ';
|
||||
rsToolTerminal = 'Terminal';
|
||||
rsToolErrorOpeningViewer = 'Error opening viewer';
|
||||
rsToolErrorOpeningEditor = 'Error opening editor';
|
||||
rsToolErrorOpeningDiffer = 'Error opening differ';
|
||||
rsToolErrorOpeningTerminal = 'Error opening terminal';
|
||||
// Configure custom columns dialog
|
||||
rsConfColDelete = 'Delete';
|
||||
rsConfColCaption = 'Caption';
|
||||
|
|
|
|||
|
|
@ -1091,73 +1091,80 @@ begin
|
|||
end;
|
||||
end;
|
||||
|
||||
sl := TStringList.Create;
|
||||
for i := 0 to SelectedFiles.Count - 1 do
|
||||
begin
|
||||
aFile := SelectedFiles[i];
|
||||
|
||||
if not (aFile.IsDirectory or aFile.IsLinkToDirectory) then
|
||||
try
|
||||
sl := TStringList.Create;
|
||||
for i := 0 to SelectedFiles.Count - 1 do
|
||||
begin
|
||||
if (log_info in gLogOptions) then
|
||||
logWrite('View.Add: ' + aFile.FullPath, lmtInfo);
|
||||
aFile := SelectedFiles[i];
|
||||
|
||||
//now test if exists View command in doublecmd.ext :)
|
||||
sViewCmd:= gExts.GetExtActionCmd(aFile, 'view');
|
||||
if not (aFile.IsDirectory or aFile.IsLinkToDirectory) then
|
||||
begin
|
||||
if (log_info in gLogOptions) then
|
||||
logWrite('View.Add: ' + aFile.FullPath, lmtInfo);
|
||||
|
||||
if (sViewCmd<>'') then
|
||||
begin
|
||||
sViewCmd := PrepareParameter(sViewCmd, aFile);
|
||||
ProcessExtCommand(sViewCmd, ActiveFrame.CurrentPath);
|
||||
// TODO:
|
||||
// If TempFileSource is used, create a wait thread that will
|
||||
// keep the TempFileSource alive until the command is finished.
|
||||
end
|
||||
else
|
||||
begin
|
||||
sl.Add(aFile.FullPath);
|
||||
end;
|
||||
end; // if selected
|
||||
end; // for
|
||||
//now test if exists View command in doublecmd.ext :)
|
||||
sViewCmd:= gExts.GetExtActionCmd(aFile, 'view');
|
||||
|
||||
// If only one file was selected then add all files in panel to the list.
|
||||
// Works only for directly accessible files and only when using internal viewer.
|
||||
if (sl.Count=1) and
|
||||
(not gExternalTools[etViewer].Enabled) and
|
||||
([fspDirectAccess, fspLinksToLocalFiles] * ActiveFrame.FileSource.Properties <> []) then
|
||||
begin
|
||||
AllFiles := ActiveFrame.CloneFiles;
|
||||
|
||||
if (fspLinksToLocalFiles in ActiveFrame.FileSource.Properties) then
|
||||
begin
|
||||
for I := 0 to AllFiles.Count - 1 do
|
||||
begin
|
||||
aFile := AllFiles[I];
|
||||
ActiveFrame.FileSource.GetLocalName(aFile);
|
||||
end;
|
||||
end;
|
||||
|
||||
n:=0;
|
||||
for i := 0 to AllFiles.Count - 1 do
|
||||
begin
|
||||
aFile := AllFiles[i];
|
||||
if not (aFile.IsDirectory or aFile.IsLinkToDirectory) then
|
||||
begin
|
||||
if n>0 then sl.Add(aFile.FullPath);
|
||||
if aFile.Name = ActiveFile.Name then n:=i;
|
||||
end;
|
||||
end;
|
||||
|
||||
for i:=0 to n-1 do
|
||||
begin
|
||||
aFile := AllFiles[i];
|
||||
if not (aFile.IsDirectory or aFile.IsLinkToDirectory) then
|
||||
if (sViewCmd<>'') then
|
||||
begin
|
||||
sViewCmd := PrepareParameter(sViewCmd, aFile);
|
||||
ProcessExtCommand(sViewCmd, ActiveFrame.CurrentPath);
|
||||
// TODO:
|
||||
// If TempFileSource is used, create a wait thread that will
|
||||
// keep the TempFileSource alive until the command is finished.
|
||||
end
|
||||
else
|
||||
begin
|
||||
sl.Add(aFile.FullPath);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end; // if selected
|
||||
end; // for
|
||||
|
||||
// if sl has files then view it
|
||||
if sl.Count > 0 then
|
||||
ShowViewerByGlobList(sl, aFileSource);
|
||||
// If only one file was selected then add all files in panel to the list.
|
||||
// Works only for directly accessible files and only when using internal viewer.
|
||||
if (sl.Count=1) and
|
||||
(not gExternalTools[etViewer].Enabled) and
|
||||
([fspDirectAccess, fspLinksToLocalFiles] * ActiveFrame.FileSource.Properties <> []) then
|
||||
begin
|
||||
AllFiles := ActiveFrame.CloneFiles;
|
||||
|
||||
if (fspLinksToLocalFiles in ActiveFrame.FileSource.Properties) then
|
||||
begin
|
||||
for I := 0 to AllFiles.Count - 1 do
|
||||
begin
|
||||
aFile := AllFiles[I];
|
||||
ActiveFrame.FileSource.GetLocalName(aFile);
|
||||
end;
|
||||
end;
|
||||
|
||||
n:=0;
|
||||
for i := 0 to AllFiles.Count - 1 do
|
||||
begin
|
||||
aFile := AllFiles[i];
|
||||
if not (aFile.IsDirectory or aFile.IsLinkToDirectory) then
|
||||
begin
|
||||
if n>0 then sl.Add(aFile.FullPath);
|
||||
if aFile.Name = ActiveFile.Name then n:=i;
|
||||
end;
|
||||
end;
|
||||
|
||||
for i:=0 to n-1 do
|
||||
begin
|
||||
aFile := AllFiles[i];
|
||||
if not (aFile.IsDirectory or aFile.IsLinkToDirectory) then
|
||||
sl.Add(aFile.FullPath);
|
||||
end;
|
||||
end;
|
||||
|
||||
// if sl has files then view it
|
||||
if sl.Count > 0 then
|
||||
ShowViewerByGlobList(sl, aFileSource);
|
||||
except
|
||||
on e: EInvalidCommandLine do
|
||||
MessageDlg(rsToolErrorOpeningViewer,
|
||||
rsMsgInvalidCommandLine + ' (' + rsToolViewer + '):' + LineEnding + e.Message,
|
||||
mtError, [mbOK], 0);
|
||||
end;
|
||||
|
||||
finally
|
||||
if Assigned(sl) then
|
||||
|
|
@ -1218,27 +1225,35 @@ begin
|
|||
SelectedFiles := ActiveFrame.CloneSelectedFiles;
|
||||
end;
|
||||
|
||||
for i := 0 to SelectedFiles.Count - 1 do
|
||||
begin
|
||||
aFile := SelectedFiles[i];
|
||||
|
||||
// For now we only process one file.
|
||||
if not (aFile.IsDirectory or aFile.IsLinkToDirectory) then
|
||||
try
|
||||
for i := 0 to SelectedFiles.Count - 1 do
|
||||
begin
|
||||
//now test if exists View command in doublecmd.ext :)
|
||||
sEditCmd:= gExts.GetExtActionCmd(aFile, 'edit');
|
||||
aFile := SelectedFiles[i];
|
||||
|
||||
if (sEditCmd <> '') then
|
||||
begin
|
||||
sEditCmd := PrepareParameter(sEditCmd, aFile);
|
||||
ProcessExtCommand(sEditCmd, aFile.Path);
|
||||
end
|
||||
else
|
||||
begin
|
||||
ShowEditorByGlob(aFile.FullPath);
|
||||
end;
|
||||
Break;
|
||||
// For now we only process one file.
|
||||
if not (aFile.IsDirectory or aFile.IsLinkToDirectory) then
|
||||
begin
|
||||
//now test if exists View command in doublecmd.ext :)
|
||||
sEditCmd:= gExts.GetExtActionCmd(aFile, 'edit');
|
||||
|
||||
if (sEditCmd <> '') then
|
||||
begin
|
||||
sEditCmd := PrepareParameter(sEditCmd, aFile);
|
||||
ProcessExtCommand(sEditCmd, aFile.Path);
|
||||
end
|
||||
else
|
||||
begin
|
||||
ShowEditorByGlob(aFile.FullPath);
|
||||
end;
|
||||
Break;
|
||||
end;
|
||||
end;
|
||||
|
||||
except
|
||||
on e: EInvalidCommandLine do
|
||||
MessageDlg(rsToolErrorOpeningEditor,
|
||||
rsMsgInvalidCommandLine + ' (' + rsToolEditor + '):' + LineEnding + e.Message,
|
||||
mtError, [mbOK], 0);
|
||||
end;
|
||||
|
||||
finally
|
||||
|
|
@ -1656,7 +1671,14 @@ var
|
|||
sCommand := sCommand + ' ' + Parameters;
|
||||
for i := 0 to CompareList.Count - 1 do
|
||||
sCommand := sCommand + ' ' + QuoteStr(CompareList.Strings[i]);
|
||||
ExecCmdFork(sCommand, RunInTerminal, '', KeepTerminalOpen);
|
||||
try
|
||||
ExecCmdFork(sCommand, RunInTerminal, '', KeepTerminalOpen);
|
||||
except
|
||||
on e: EInvalidCommandLine do
|
||||
MessageDlg(rsToolErrorOpeningDiffer,
|
||||
rsMsgInvalidCommandLine + ' (' + rsToolDiffer + '):' + LineEnding + e.Message,
|
||||
mtError, [mbOK], 0);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
|
@ -2153,7 +2175,14 @@ begin
|
|||
if not frmMain.edtCommand.Focused then
|
||||
begin
|
||||
mbSetCurrentDir(frmMain.ActiveFrame.CurrentPath);
|
||||
ExecCmdFork(gRunTerm);
|
||||
try
|
||||
ExecCmdFork(gRunTerm);
|
||||
except
|
||||
on e: EInvalidCommandLine do
|
||||
MessageDlg(rsToolErrorOpeningTerminal,
|
||||
rsMsgInvalidCommandLine + ' (' + rsToolTerminal + '):' + LineEnding + e.Message,
|
||||
mtError, [mbOK], 0);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
|
|
|||
|
|
@ -45,8 +45,8 @@ Function ShowViewerByGlobList(const FilesToView: TStringList;
|
|||
implementation
|
||||
|
||||
uses
|
||||
SysUtils, Process, UTF8Process, LCLProc, uGlobs, uOSUtils, fEditor, fViewer,
|
||||
uDCUtils, uTempFileSystemFileSource;
|
||||
SysUtils, Process, UTF8Process, LCLProc, Dialogs, Forms,
|
||||
uGlobs, uOSUtils, fEditor, fViewer, uDCUtils, uTempFileSystemFileSource, uLng;
|
||||
|
||||
function RunExtTool(const ExtTool: TExternalToolOptions; sFileName: String): String;
|
||||
begin
|
||||
|
|
@ -60,10 +60,19 @@ end;
|
|||
function ShowEditorByGlob(sFileName:String):Boolean;
|
||||
begin
|
||||
if gExternalTools[etEditor].Enabled then
|
||||
RunExtTool(gExternalTools[etEditor], sFileName)
|
||||
begin
|
||||
try
|
||||
RunExtTool(gExternalTools[etEditor], sFileName);
|
||||
except
|
||||
on e: EInvalidCommandLine do
|
||||
MessageDlg(rsToolErrorOpeningEditor,
|
||||
rsMsgInvalidCommandLine + ' (' + rsToolEditor + '):' + LineEnding + e.Message,
|
||||
mtError, [mbOK], 0);
|
||||
end;
|
||||
end
|
||||
else
|
||||
ShowEditor(sFileName);
|
||||
Result:=True;
|
||||
Result:=True;
|
||||
end;
|
||||
|
||||
function ShowViewerByGlob(sFileName:String):Boolean;
|
||||
|
|
@ -71,7 +80,16 @@ var
|
|||
sl:TStringList;
|
||||
begin
|
||||
if gExternalTools[etViewer].Enabled then
|
||||
RunExtTool(gExternalTools[etViewer], sFileName)
|
||||
begin
|
||||
try
|
||||
RunExtTool(gExternalTools[etViewer], sFileName);
|
||||
except
|
||||
on e: EInvalidCommandLine do
|
||||
MessageDlg(rsToolErrorOpeningViewer,
|
||||
rsMsgInvalidCommandLine + ' (' + rsToolViewer + '):' + LineEnding + e.Message,
|
||||
mtError, [mbOK], 0);
|
||||
end;
|
||||
end
|
||||
else
|
||||
begin
|
||||
sl:=TStringList.Create;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue