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

shellext: copy truncated strings in GetCommandString

Changeset 82b700937130

Parent 27ed9f9ad55a

by Adrian Buehlmann

Changes to one file · Browse files at 82b700937130 Showing diff from parent 27ed9f9ad55a Diff from another changeset...

 
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
 
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
@@ -471,37 +471,34 @@
  "CShellExt::GetCommandString: can't find idCmd " << idCmd);   }   - bool copied = false; + if (cchMax < 1) + return NOERROR; +   size_t size = 0;     if (uFlags & GCS_UNICODE)   {   wchar_t* const dest = reinterpret_cast<wchar_t*>(pszName); - *dest = 0;   const wchar_t* const src = _WCSTR(psz); + + wcsncpy(dest, src, cchMax-1); + *(dest + cchMax-1) = 0; +   size = wcslen(src); - if (size < cchMax) - { - wcscpy(dest, src); - copied = true; - }   }   else   { - *pszName = 0; + strncpy(pszName, psz, cchMax-1); + *(pszName + cchMax-1) = 0; +   size = strlen(psz); - if (size < cchMax) - { - strcpy(pszName, psz); - copied = true; - }   }   - if (!copied) + if (size > cchMax-1)   {   TDEBUG_TRACE( - "CShellExt::GetCommandString: error: source string length (" - << size << ") exceeds target buffer size (" << cchMax << ")"); + "CShellExt::GetCommandString: string was truncated: size = " + << size << ", cchMax = " << cchMax);   }     return NOERROR;