@@ -200,9 +200,11 @@ static void RemoveQuotes(IN_Z_CAP(bufferSize) char *pBuf, intp bufferSize)
200
200
if (pBuf[0 ] == ' "' )
201
201
V_memmove (pBuf, pBuf + 1 , bufferSize - 1 );
202
202
203
- const size_t end = strlen (pBuf) - 1 ;
203
+ const intp end = bufferSize - 2 ;
204
204
205
- if (pBuf[end] == ' "' )
205
+ if (end <= 0 )
206
+ pBuf[0 ] = ' \0 ' ;
207
+ else if (pBuf[end] == ' "' )
206
208
pBuf[end] = ' \0 ' ;
207
209
}
208
210
@@ -234,6 +236,7 @@ void SplitFileNameFromPath(char* szDocLongPath,
234
236
p = strrchr (szDocLongPath, ' \\ ' );
235
237
if (!p)
236
238
p = strrchr (szDocLongPath, ' /' );
239
+
237
240
if (p)
238
241
{
239
242
// got the filepart
@@ -267,8 +270,8 @@ bool RunCommands(CCommandArray& Commands, LPCTSTR pszOrigDocName, CWnd *parent)
267
270
char szDocShortPath[MAX_PATH] = {0 }, szDocShortName[MAX_PATH] = {0 },
268
271
szDocShortExt[MAX_PATH] = {0 };
269
272
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) );
272
275
273
276
// split them up
274
277
SplitFileNameFromPath (szDocLongPath, szDocLongName, szDocLongExt);
@@ -324,7 +327,7 @@ bool RunCommands(CCommandArray& Commands, LPCTSTR pszOrigDocName, CWnd *parent)
324
327
if (p[0 ] == ' ' )
325
328
{
326
329
// found a space-separator
327
- p[0 ] = 0 ;
330
+ p[0 ] = ' \0 ' ;
328
331
329
332
p++;
330
333
@@ -344,7 +347,7 @@ bool RunCommands(CCommandArray& Commands, LPCTSTR pszOrigDocName, CWnd *parent)
344
347
if (p[0 ] == ' \" ' )
345
348
{
346
349
// found the end
347
- if (p[1 ] == 0 )
350
+ if (p[1 ] == ' \0 ' )
348
351
bDone = TRUE ;
349
352
p[1 ] = 0 ; // kick its ass
350
353
p += 2 ;
@@ -376,8 +379,8 @@ bool RunCommands(CCommandArray& Commands, LPCTSTR pszOrigDocName, CWnd *parent)
376
379
377
380
if (cmd.iSpecialCmd == CCCopyFile && iArg == 3 )
378
381
{
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 ]) );
381
384
382
385
// don't copy if we're already there
383
386
if (stricmp (ppParms[1 ], ppParms[2 ]) != 0 &&
@@ -389,7 +392,7 @@ bool RunCommands(CCommandArray& Commands, LPCTSTR pszOrigDocName, CWnd *parent)
389
392
}
390
393
else if (cmd.iSpecialCmd == CCDelFile && iArg == 2 )
391
394
{
392
- RemoveQuotes (ppParms[1 ], ssize (ppParms) - 1 );
395
+ RemoveQuotes (ppParms[1 ], V_strlen (ppParms[ 1 ]) );
393
396
if (!DeleteFile (ppParms[1 ]))
394
397
{
395
398
bError = TRUE ;
@@ -398,8 +401,8 @@ bool RunCommands(CCommandArray& Commands, LPCTSTR pszOrigDocName, CWnd *parent)
398
401
}
399
402
else if (cmd.iSpecialCmd == CCRenameFile && iArg == 3 )
400
403
{
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 ]) );
403
406
if (rename (ppParms[1 ], ppParms[2 ]))
404
407
{
405
408
bError = TRUE ;
@@ -408,7 +411,7 @@ bool RunCommands(CCommandArray& Commands, LPCTSTR pszOrigDocName, CWnd *parent)
408
411
}
409
412
else if (cmd.iSpecialCmd == CCChangeDir && iArg == 2 )
410
413
{
411
- RemoveQuotes (ppParms[1 ], ssize (ppParms) - 1 );
414
+ RemoveQuotes (ppParms[1 ], V_strlen (ppParms[ 1 ]) );
412
415
if (mychdir (ppParms[1 ]) == -1 )
413
416
{
414
417
bError = TRUE ;
@@ -433,7 +436,9 @@ bool RunCommands(CCommandArray& Commands, LPCTSTR pszOrigDocName, CWnd *parent)
433
436
// This is necessary for Steam to find the correct Steam DLL (it
434
437
// uses the current working directory to search).
435
438
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));
437
442
V_StripFilename (szDir);
438
443
439
444
mychdir (szDir);
0 commit comments