Skip to content

Commit 8ba487a

Browse files
committed
hammer: Fix double quotes removal from command line
1 parent 0636071 commit 8ba487a

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

hammer/runcommands.cpp

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,11 @@ static void RemoveQuotes(IN_Z_CAP(bufferSize) char *pBuf, intp bufferSize)
200200
if (pBuf[0] == '"')
201201
V_memmove(pBuf, pBuf + 1, bufferSize - 1);
202202

203-
const size_t end = strlen(pBuf) - 1;
203+
const intp end = bufferSize - 2;
204204

205-
if (pBuf[end] == '"')
205+
if (end <= 0)
206+
pBuf[0] = '\0';
207+
else if (pBuf[end] == '"')
206208
pBuf[end] = '\0';
207209
}
208210

@@ -234,6 +236,7 @@ void SplitFileNameFromPath(char* szDocLongPath,
234236
p = strrchr(szDocLongPath, '\\');
235237
if(!p)
236238
p = strrchr(szDocLongPath, '/');
239+
237240
if(p)
238241
{
239242
// got the filepart
@@ -267,8 +270,8 @@ bool RunCommands(CCommandArray& Commands, LPCTSTR pszOrigDocName, CWnd *parent)
267270
char szDocShortPath[MAX_PATH] = {0}, szDocShortName[MAX_PATH] = {0},
268271
szDocShortExt[MAX_PATH] = {0};
269272

270-
GetFullPathName(pszOrigDocName, MAX_PATH, szDocLongPath, NULL);
271-
GetShortPathName(pszOrigDocName, szDocShortPath, MAX_PATH);
273+
GetFullPathName(pszOrigDocName, std::size(szDocLongPath), szDocLongPath, nullptr);
274+
GetShortPathName(pszOrigDocName, szDocShortPath, std::size(szDocShortPath));
272275

273276
// split them up
274277
SplitFileNameFromPath(szDocLongPath, szDocLongName, szDocLongExt);
@@ -324,7 +327,7 @@ bool RunCommands(CCommandArray& Commands, LPCTSTR pszOrigDocName, CWnd *parent)
324327
if(p[0] == ' ')
325328
{
326329
// found a space-separator
327-
p[0] = 0;
330+
p[0] = '\0';
328331

329332
p++;
330333

@@ -344,7 +347,7 @@ bool RunCommands(CCommandArray& Commands, LPCTSTR pszOrigDocName, CWnd *parent)
344347
if(p[0] == '\"')
345348
{
346349
// found the end
347-
if(p[1] == 0)
350+
if(p[1] == '\0')
348351
bDone = TRUE;
349352
p[1] = 0; // kick its ass
350353
p += 2;
@@ -376,8 +379,8 @@ bool RunCommands(CCommandArray& Commands, LPCTSTR pszOrigDocName, CWnd *parent)
376379

377380
if(cmd.iSpecialCmd == CCCopyFile && iArg == 3)
378381
{
379-
RemoveQuotes(ppParms[1], ssize(ppParms) - 1);
380-
RemoveQuotes(ppParms[2], ssize(ppParms) - 2);
382+
RemoveQuotes(ppParms[1], V_strlen(ppParms[1]));
383+
RemoveQuotes(ppParms[2], V_strlen(ppParms[2]));
381384

382385
// don't copy if we're already there
383386
if (stricmp(ppParms[1], ppParms[2]) != 0 &&
@@ -389,7 +392,7 @@ bool RunCommands(CCommandArray& Commands, LPCTSTR pszOrigDocName, CWnd *parent)
389392
}
390393
else if(cmd.iSpecialCmd == CCDelFile && iArg == 2)
391394
{
392-
RemoveQuotes(ppParms[1], ssize(ppParms) - 1);
395+
RemoveQuotes(ppParms[1], V_strlen(ppParms[1]));
393396
if(!DeleteFile(ppParms[1]))
394397
{
395398
bError = TRUE;
@@ -398,8 +401,8 @@ bool RunCommands(CCommandArray& Commands, LPCTSTR pszOrigDocName, CWnd *parent)
398401
}
399402
else if(cmd.iSpecialCmd == CCRenameFile && iArg == 3)
400403
{
401-
RemoveQuotes(ppParms[1], ssize(ppParms) - 1);
402-
RemoveQuotes(ppParms[2], ssize(ppParms) - 2);
404+
RemoveQuotes(ppParms[1], V_strlen(ppParms[1]));
405+
RemoveQuotes(ppParms[2], V_strlen(ppParms[2]));
403406
if(rename(ppParms[1], ppParms[2]))
404407
{
405408
bError = TRUE;
@@ -408,7 +411,7 @@ bool RunCommands(CCommandArray& Commands, LPCTSTR pszOrigDocName, CWnd *parent)
408411
}
409412
else if(cmd.iSpecialCmd == CCChangeDir && iArg == 2)
410413
{
411-
RemoveQuotes(ppParms[1], ssize(ppParms) - 1);
414+
RemoveQuotes(ppParms[1], V_strlen(ppParms[1]));
412415
if(mychdir(ppParms[1]) == -1)
413416
{
414417
bError = TRUE;
@@ -433,7 +436,9 @@ bool RunCommands(CCommandArray& Commands, LPCTSTR pszOrigDocName, CWnd *parent)
433436
// This is necessary for Steam to find the correct Steam DLL (it
434437
// uses the current working directory to search).
435438
char szDir[MAX_PATH];
436-
Q_strncpy(szDir, szNewRun, sizeof(szDir));
439+
V_strcpy_safe(szDir, szNewRun);
440+
// dimhotepus: Strip quotes around dir.
441+
RemoveQuotes(szDir, ssize(szDir));
437442
V_StripFilename(szDir);
438443

439444
mychdir(szDir);

0 commit comments

Comments
 (0)