Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 0.8, 0.8.1, and 0.8.2

shellext: check string sizes on CShellExt::GetCommandString

Changeset 6be9d400438d

Parent 73aee702785a

by Adrian Buehlmann

Changes to one file · Browse files at 6be9d400438d Showing diff from parent 73aee702785a Diff from another changeset...

 
456
457
458
459
460
 
461
462
463
464
465
 
466
467
468
469
470
471
 
472
473
474
475
476
477
478
479
 
 
 
480
481
482
 
 
 
 
 
 
 
 
 
483
484
485
486
 
 
 
 
 
 
 
487
 
 
 
 
 
 
 
 
488
489
490
 
456
457
458
 
 
459
460
461
462
463
464
465
466
467
468
469
470
 
471
472
473
474
475
476
 
477
478
479
480
481
482
483
 
484
485
486
487
488
489
490
491
492
493
494
495
 
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
@@ -456,35 +456,59 @@
  UINT_PTR idCmd, UINT uFlags, UINT FAR *reserved,   LPSTR pszName, UINT cchMax)  { - *pszName = 0; - char *psz; + const char *psz = "";     TDEBUG_TRACE(   "CShellExt::GetCommandString: idCmd = " << idCmd   << ", uFlags = " << uFlags   ); +   MenuIdCmdMap::iterator iter = MenuIdMap.find(static_cast<UINT>(idCmd));   if (iter != MenuIdMap.end())   {   TDEBUG_TRACE(   "CShellExt::GetCommandString: name = " << iter->second.name); - psz = (char*)iter->second.helpText.c_str(); + psz = iter->second.helpText.c_str();   }   else   {   TDEBUG_TRACE(   "CShellExt::GetCommandString: can't find idCmd " << idCmd); - psz = "";   }   + bool copied = false; + size_t size = 0; +   if (uFlags & GCS_UNICODE)   { - wcscpy((wchar_t*)pszName, _WCSTR(psz)); + wchar_t* const dest = reinterpret_cast<wchar_t*>(pszName); + *dest = 0; + const wchar_t* const src = _WCSTR(psz); + size = wcslen(src); + if (size < cchMax) + { + wcscpy(dest, src); + copied = true; + }   }   else   { - strcpy((char*)pszName, psz); + *pszName = 0; + size = strlen(psz); + if (size < cchMax) + { + strcpy(pszName, psz); + copied = true; + }   } + + if (!copied) + { + TDEBUG_TRACE( + "CShellExt::GetCommandString: error: source string length (" + << size << ") exceeds target buffer size (" << cchMax << ")"); + } +   return NOERROR;  }