Changeset 1154

Show
Ignore:
Timestamp:
09/05/08 22:37:19 (3 months ago)
Author:
stevenhl
Message:

Correct FreeCnrItemData? pszDisplayName pointer overlap check

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/dll/filldir.c

    r1146 r1154  
    4747  02 Aug 08 GKY Remove redundant strcpys from inner loop 
    4848  23 Aug 08 GKY Free pszDisplayName when appropriate 
    49   01 Sep 08 GKY Updated FreeCnrItemData toprevent trap in strrchr if pci->pszFileName is NULL. 
     49  01 Sep 08 GKY Updated FreeCnrItemData to prevent trap in strrchr if pci->pszFileName is NULL. 
     50  05 Sep 08 SHL Correct FreeCnrItemData pszDisplayName pointer overlap check 
    5051 
    5152***********************************************************************/ 
     
    5354#include <stdlib.h> 
    5455#include <string.h> 
     56#include <malloc.h>                     // _msize _heapchk 
    5557#include <ctype.h> 
    56  
    57 #if 0 // fixme to disable or to be configurable 
    58 #include <malloc.h>                     // _heapchk 
    59 #endif 
    6058 
    6159#define INCL_DOS 
     
    270268#   ifdef FORTIFY 
    271269    { 
    272       unsigned tid = GetTidForWindow(hwndCnr); 
    273       // char buf[256]; 
    274       if (tid == 1) 
     270      if (dcd->type != TREE_FRAME) 
    275271        Fortify_ChangeScope(pci->pszFileName, -1); 
    276       else 
     272      else { 
    277273        Fortify_SetOwner(pci->pszFileName, 1); 
    278       // sprintf(buf, "Owner forced to %u", GetTidForWindow(hwndCnr)); 
    279       // Fortify_LabelPointer(pci->pszFmtFileSize, buf); 
     274        Fortify_SetScope(pci->pszFileName, 2); 
     275      } 
    280276    } 
    281277#   endif 
     
    374370            pci->pszLongName = xstrdup(value + (sizeof(USHORT) * 2), pszSrcFile, __LINE__); 
    375371#           ifdef FORTIFY 
    376             { 
    377               unsigned tid = GetTidForWindow(hwndCnr); 
    378               // char buf[256]; 
    379               if (tid == 1) 
    380                 Fortify_ChangeScope(pci->pszLongName, -1); 
    381               else 
    382                 Fortify_SetOwner(pci->pszLongName, 1); 
    383               // sprintf(buf, "Owner forced to %u", GetTidForWindow(hwndCnr)); 
    384               // Fortify_LabelPointer(pci->pszFmtFileSize, buf); 
    385             } 
     372            { 
     373              unsigned tid = GetTidForWindow(hwndCnr); 
     374              if (tid == 1) 
     375                Fortify_ChangeScope(pci->pszLongName, -1); 
     376              else 
     377                Fortify_SetOwner(pci->pszLongName, 1); 
     378            } 
    386379#           endif 
    387380          } 
     
    465458    { 
    466459      unsigned tid = GetTidForWindow(hwndCnr); 
    467       // char buf[256]; 
    468460      if (tid == 1) 
    469461        Fortify_ChangeScope(pci->pszFmtFileSize, -1); 
    470462      else 
    471463        Fortify_SetOwner(pci->pszFmtFileSize, 1); 
    472       // sprintf(buf, "Owner forced to %u", GetTidForWindow(hwndCnr)); 
    473       // Fortify_LabelPointer(pci->pszFmtFileSize, buf); 
    474464    } 
    475465#   endif 
     
    529519} // FillInRecordFromFFB 
    530520 
    531 ULONGLONG FillInRecordFromFSA(HWND hwndCnr, PCNRITEM pci, 
     521ULONGLONG FillInRecordFromFSA(HWND hwndCnr, 
     522                              PCNRITEM pci, 
    532523                              const PSZ pszFileName, 
    533524                              const PFILESTATUS4L pfsa4, 
    534                               const BOOL partial, DIRCNRDATA * dcd)     // Optional 
     525                              const BOOL partial, 
     526                              DIRCNRDATA *dcd)  // Optional 
    535527{ 
    536528  HPOINTER hptr; 
     
    691683  //comma format the file size for large file support 
    692684  { 
    693   CHAR szBuf[30]; 
     685    CHAR szBuf[30]; 
    694686    CommaFmtULL(szBuf, sizeof(szBuf), pfsa4->cbFile, ' '); 
    695687    pci->pszFmtFileSize = xstrdup(szBuf, pszSrcFile, __LINE__); 
     688#   ifdef FORTIFY 
     689    { 
     690      if (dcd && dcd->type == TREE_FRAME) { 
     691        // Will be freed in TreeCnrWndProc WM_DESTROY 
     692        // Fortify_SetOwner(pci->pszFmtFileSize, 1); 
     693        Fortify_SetScope(pci->pszFmtFileSize, 2); 
     694      } 
     695    } 
     696#   endif 
    696697  } 
    697698  pci->date.day = pfsa4->fdateLastWrite.day; 
     
    12891290          pci->rc.hptrIcon = hptrDunno; 
    12901291          pci->pszFileName = xstrdup(szDrive, pszSrcFile, __LINE__); 
    1291           //strcpy(pci->pszFileName, szDrive); 
     1292          // strcpy(pci->pszFileName, szDrive); // 22 Jul 08 SHL No need to do this twice 
     1293#         ifdef FORTIFY 
     1294          // Will be freed by TreeCnrWndProc WM_DESTROY 
     1295          Fortify_SetScope(pci->pszFileName, 2); 
     1296#         endif 
    12921297          pci->pszDisplayName = pci->pszFileName; 
    12931298          pci->rc.pszIcon = pci->pszFileName; 
     
    13901395        char *p, *pp; 
    13911396 
    1392         p = pszTreeEnvVarList; 
     1397        p = pszTreeEnvVarList; 
    13931398        while (*p == ';') 
    13941399          p++; 
     
    16421647    free(psz); 
    16431648  } 
     1649 
     1650  // Check double free 
    16441651  if (!pci->pszFileName) 
    1645     DbgMsg(pszSrcFile, __LINE__, "FreeCnrItemData pci->pszFileName is NULL"); 
    1646   if (pci->pszFileName && 
     1652    DbgMsg(pszSrcFile, __LINE__, "FreeCnrItemData pci->pszFileName already NULL"); 
     1653 
     1654  // Bypass free if pszDisplayName points into pszFileName buffer 
     1655  // 05 Sep 08 SHL Correct pointer overlap compare logic 
     1656  if (pci->pszDisplayName != pci->pszFileName && 
    16471657      pci->pszDisplayName && 
    1648       pci->pszDisplayName != NullStr && 
    1649       pci->pszDisplayName != pci->pszFileName && 
    1650       pci->pszDisplayName != strrchr(pci->pszFileName, '\\') && 
    1651       pci->pszDisplayName != strrchr(pci->pszFileName, ':') && 
    1652       pci->pszDisplayName != strrchr(pci->pszFileName, ':') + 1 && 
    1653       pci->pszDisplayName != strrchr(pci->pszFileName, '\\') + 1) { 
    1654     psz = pci->pszDisplayName; 
    1655     //pci->pszDisplayName = NullStr; 
    1656     pci->pszDisplayName = NULL;         // for debug 
    1657     free(psz); 
    1658 } 
     1658      pci->pszDisplayName != NullStr) { 
     1659    if (!pci->pszFileName || 
     1660        pci->pszDisplayName < pci->pszFileName || 
     1661        pci->pszDisplayName >= pci->pszFileName + _msize(pci->pszFileName)) 
     1662    { 
     1663      psz = pci->pszDisplayName; 
     1664      // pci->pszDisplayName = NullStr; 
     1665      pci->pszDisplayName = NULL;               // for debug 
     1666      free(psz); 
     1667    } 
     1668  } 
    16591669 
    16601670  if (pci->pszFileName && pci->pszFileName != NullStr) {