From 06e17cd8f54d269224f85513825f1418daba0239 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Sat, 12 Feb 2022 15:42:15 -0600 Subject: [PATCH] Give an error if file names or command-line parameters are too long. The source file name, keep name, NAMES= string, and cc= string are all restricted to 255 characters, but these limits were not previously enforced, and exceeding them could lead to strange behavior. --- CC.pas | 24 +++++++++++++++++------- CCommon.pas | 1 + MM.pas | 2 ++ 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/CC.pas b/CC.pas index 8554a44..323491f 100644 --- a/CC.pas +++ b/CC.pas @@ -36,7 +36,7 @@ begin {cc} {make sure we quit with restart set} SystemQuitFlags($4000); -{get the command line info} +{initialize file names and parameter strings} includeFileGS.maxSize := maxPath+4; includeFileGS.theString.size := 0; for i := 1 to maxPath do @@ -44,6 +44,14 @@ for i := 1 to maxPath do outFileGS := includeFileGS; partialFileGS := includeFileGS; infoStringGS := includeFileGS; + +{check the version number} +vDCBGS.pCount := 1; +VersionGS(vDCBGS); +if (ToolError <> 0) or (vDCBGS.version[1] < '2') then + TermError(10); + +{get the command line info} with liDCBGS do begin pCount := 11; sFile := @includeFileGS; @@ -52,6 +60,14 @@ with liDCBGS do begin iString := @infoStringGS; end; {with} GetLInfoGS(liDCBGS); +if ToolError <> 0 then begin {check for buffTooSmall errors} + includeFileGS.theString.size := 0; + outFileGS.theString.size := 0; + partialFileGS.theString.size := 0; + infoStringGS.theString.size := 0; + enterEditor := false; + TermError(13); + end; {if} sourceFileGS := includeFileGS; doingPartial := partialFileGS.theString.size <> 0; with liDCBGS do begin @@ -70,12 +86,6 @@ with liDCBGS do begin if list then {we don't need both...} progress := false; -{check the version number} -vDCBGS.pCount := 1; -VersionGS(vDCBGS); -if vDCBGS.version[1] < '2' then - TermError(10); - {write the header} if list or progress then begin writeln('ORCA/C ', versionStr); diff --git a/CCommon.pas b/CCommon.pas index 40f01f8..7a78183 100644 --- a/CCommon.pas +++ b/CCommon.pas @@ -999,6 +999,7 @@ case errnum of {print the error} 10: msg := 'ORCA/C requires version 2.0 or later of the shell'; 11: msg := 'The program is too large to compile to memory -- use Compile to Disk'; 12: msg := 'Invalid sym file detected. Re-run ORCA/C to proceed.'; + 13: msg := 'file name or command-line parameter is too long'; otherwise: begin msg := ''; Error(57); diff --git a/MM.pas b/MM.pas index 96b6d4d..d8ff341 100644 --- a/MM.pas +++ b/MM.pas @@ -233,6 +233,8 @@ procedure MMQuit; begin {MMQuit} DisposeAll(globalID); DisposeAll(localID); +globalID := 0; {do not use old IDs after restart} +localID := 0; end; {MMQuit} end.