Changeset 1077

Show
Ignore:
Timestamp:
07/18/08 20:11:54 (3 months ago)
Author:
stevenhl
Message:

Enhance Fortify infrastructure
Add Fortify_SetOwner Fortify_ChangeOwner Fortify_ChangeScope
Add FORTIFY_VERBOSE_SCOPE_ENTER_EXIT support
Add more fm/2 Fortify tooling and rework existing tooling for correct nesting
Still lots to do for cross-thread allocations
Add misc.h
Add walkem.h

Location:
trunk
Files:
2 added
18 modified

Legend:

Unmodified
Added
Removed
  • trunk/dll/arccnrs.c

    r1076 r1077  
    339339  if (pai->pszFileName && pai->pszFileName != NullStr) { 
    340340    psz = pai->pszFileName; 
    341     pai->pszFileName = NULL; 
     341    pai->pszFileName = NULL;            // 08 Jul 08 SHL was NulStr 
    342342    free(psz); 
    343343  } 
    … …  
    12301230 
    12311231  switch (msg) { 
     1232  case WM_CREATE: 
     1233    DbgMsg(pszSrcFile, __LINE__, "WM_CREATE mp1 %p mp2 %p", mp1, mp2);  // 18 Jul 08 SHL fixme 
     1234    break; 
     1235 
    12321236  case DM_PRINTOBJECT: 
    12331237  case DM_DISCARDOBJECT: 
    … …  
    13471351 
    13481352  case UM_SETUP: 
     1353#   ifdef FORTIFY 
     1354    Fortify_EnterScope(); 
     1355#   endif 
    13491356    dcd = WinQueryWindowPtr(hwnd, QWL_USER); 
    13501357    if (!dcd) { 
    … …  
    13531360    } 
    13541361    else { 
     1362#     ifdef FORTIFY 
     1363      Fortify_ChangeOwner(dcd); 
     1364#     endif 
    13551365      /* set unique id */ 
    13561366      WinSetWindowUShort(hwnd, QWS_ID, ARCOBJ_FRAME + (ARC_FRAME - dcd->id)); 
    … …  
    15001510 
    15011511      if (li && li->list && li->list[0]) { 
    1502         printf("%x/r", li->type); fflush(stdout); 
     1512        printf("%x/r", li->type); fflush(stdout); 
    15031513        switch (li->type) { 
    15041514        case IDM_ARCHIVE: 
    … …  
    15651575        case IDM_DELETE: 
    15661576          { 
    1567             CHAR *endofit; 
    1568             PSZ pszCmdLine; 
     1577            CHAR *endofit; 
     1578            PSZ pszCmdLine; 
    15691579            INT z; 
    15701580            CHECKLIST ck; 
    … …  
    15921602            li->list = ck.list; 
    15931603            if (!li->list || !li->list[0]) 
    1594               break; 
    1595             pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__); 
    1596             if (!pszCmdLine) 
    1597               break; 
     1604              break; 
     1605            pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__); 
     1606            if (!pszCmdLine) 
     1607              break; 
    15981608            strcpy(pszCmdLine, li->type == IDM_DELETE ? 
    15991609                         dcd->info->delete : 
    … …  
    16131623                      (fArcStuffVisible ? 0 : BACKGROUND | MINIMIZED), 
    16141624                      hwnd, pszSrcFile, __LINE__, NullStr, NULL, "%s", pszCmdLine); 
    1615               *endofit = 0; 
    1616               free(pszCmdLine); 
     1625              *endofit = 0; 
     1626              free(pszCmdLine); 
    16171627            } while (li->list[x]); 
    16181628            PostMsg(dcd->hwndCnr, UM_RESCAN, MPFROMSHORT(1), MPVOID); 
    … …  
    16391649        case IDM_OPENSETTINGS: 
    16401650          { 
    1641             CHAR *endofit, *ptr; 
    1642             PSZ pszCmdLine; 
     1651            CHAR *endofit, *ptr; 
     1652            PSZ pszCmdLine; 
    16431653            INT z; 
    16441654            if ((li->type == IDM_EXTRACT && !li->info->extract) || 
    … …  
    16991709            } 
    17001710            if (!li->list || !li->list[0]) 
    1701               break; 
    1702             pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__); 
    1703             if (!pszCmdLine) 
    1704               break; 
     1711              break; 
     1712            pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__); 
     1713            if (!pszCmdLine) 
     1714              break; 
    17051715            strcpy(pszCmdLine, 
    17061716                   (li->type == IDM_EXTRACT || 
    … …  
    17391749                      (fArcStuffVisible ? 0 : BACKGROUND | MINIMIZED) | 
    17401750                      WAIT, hwnd, pszSrcFile, __LINE__, 
    1741                       li->targetpath, NULL, "%s", pszCmdLine); 
     1751                      li->targetpath, NULL, "%s", pszCmdLine); 
    17421752              *endofit = 0; 
    17431753            } while (li->list[x]); 
    … …  
    17571767                p = xmalloc(strlen(temp) + strlen(li->targetpath) + 2, 
    17581768                            pszSrcFile, __LINE__); 
    1759                 if (p) { 
    1760                   BldFullPathName(p, li->targetpath, temp); 
     1769                if (p) { 
     1770                  BldFullPathName(p, li->targetpath, temp); 
    17611771                  /*strcpy(p, li->targetpath); 
    17621772                  if (p[strlen(p) - 1] != '\\') 
    … …  
    18271837                    } 
    18281838                  } 
    1829                 } 
     1839                } 
    18301840                BldFullPathName(pszCmdLine, li->targetpath, li->list[x]); 
    18311841                temp = li->list[x]; 
    1832                 li->list[x] = xstrdup(pszCmdLine, pszSrcFile, __LINE__); 
     1842                li->list[x] = xstrdup(pszCmdLine, pszSrcFile, __LINE__); 
    18331843                if (!li->list[x]) 
    18341844                  li->list[x] = temp; 
    18351845                else 
    18361846                  xfree(temp, pszSrcFile, __LINE__); 
    1837               } 
    1838               free(pszCmdLine); 
     1847              } 
     1848              free(pszCmdLine); 
    18391849              if (li->type == IDM_VIEW || li->type == IDM_EDIT) { 
    18401850 
    … …  
    18561866              if (li->type == IDM_MCIPLAY) { 
    18571867 
    1858                 FILE *fp; 
    1859                 CHAR szTempFile[CCHMAXPATH]; 
    1860  
    1861                 BldFullPathName(szTempFile, pTmpDir, "$FM2PLAY.$$$"); 
     1868                FILE *fp; 
     1869                CHAR szTempFile[CCHMAXPATH]; 
     1870 
     1871                BldFullPathName(szTempFile, pTmpDir, "$FM2PLAY.$$$"); 
    18621872                fp = xfopen(szTempFile, "w", pszSrcFile, __LINE__); 
    18631873                if (fp) { 
    … …  
    18661876                    fprintf(fp, "%s\n", li->list[x]); 
    18671877                  fprintf(fp, ";end\n"); 
    1868                   fclose(fp); 
    1869                   strrev(szTempFile); 
    1870                   strcat(szTempFile, "@/"); 
    1871                   strrev(szTempFile); 
     1878                  fclose(fp); 
     1879                  strrev(szTempFile); 
     1880                  strcat(szTempFile, "@/"); 
     1881                  strrev(szTempFile); 
    18721882                  RunFM2Util("FM2PLAY.EXE", szTempFile); 
    18731883                } 
    … …  
    19131923                       li->type == IDM_OPENSETTINGS) { 
    19141924                WORKER *wk; 
    1915 #               ifdef FORTIFY 
    1916                 Fortify_EnterScope(); 
    1917 #               endif 
     1925#               ifdef FORTIFY 
     1926                Fortify_EnterScope(); 
     1927#               endif 
    19181928                wk = xmallocz(sizeof(WORKER), pszSrcFile, __LINE__); 
    19191929                if (!wk) 
    1920                   FreeListInfo(li); 
     1930                  FreeListInfo(li); 
    19211931                else { 
    1922                   wk->size = sizeof(WORKER); 
    1923                   wk->hwndCnr = dcd->hwndCnr; 
    1924                   wk->hwndParent = dcd->hwndParent; 
    1925                   wk->hwndFrame = dcd->hwndFrame; 
    1926                   wk->hwndClient = dcd->hwndClient; 
    1927                   wk->li = li; 
    1928                   strcpy(wk->directory, dcd->directory); 
    1929                   if (_beginthread(Action, NULL, 122880, (PVOID) wk) == -1) { 
    1930                     Runtime_Error(pszSrcFile, __LINE__, 
    1931                                   GetPString(IDS_COULDNTSTARTTHREADTEXT)); 
    1932                     free(wk); 
    1933                     FreeListInfo((LISTINFO *) mp1); 
    1934 #                   ifdef FORTIFY 
    1935                     Fortify_LeaveScope(); 
    1936 #                   endif 
    1937                   } 
    1938         } 
    1939  
     1932                  wk->size = sizeof(WORKER); 
     1933                  wk->hwndCnr = dcd->hwndCnr; 
     1934                  wk->hwndParent = dcd->hwndParent; 
     1935                  wk->hwndFrame = dcd->hwndFrame; 
     1936                  wk->hwndClient = dcd->hwndClient; 
     1937                  wk->li = li; 
     1938                  strcpy(wk->directory, dcd->directory); 
     1939                  if (_beginthread(Action, NULL, 122880, (PVOID) wk) == -1) { 
     1940                    Runtime_Error(pszSrcFile, __LINE__, 
     1941                                  GetPString(IDS_COULDNTSTARTTHREADTEXT)); 
     1942                    free(wk); 
     1943                    FreeListInfo((LISTINFO *) mp1); 
     1944                  } 
     1945                } 
     1946#               ifdef FORTIFY 
     1947                Fortify_LeaveScope(); 
     1948#               endif 
    19401949              } 
    19411950              else { 
    … …  
    19541963                    else 
    19551964                      viewtype = 0; 
     1965#                   ifdef FORTIFY 
     1966                    Fortify_EnterScope(); 
     1967#                   endif 
    19561968                    temp = xstrdup(li->list[x], pszSrcFile, __LINE__); 
    19571969                    if (temp) { 
    … …  
    19641976                        free(temp); 
    19651977                    } 
     1978#                   ifdef FORTIFY 
     1979                    DosSleep(1);        // Allow MassAction to take ownership 
     1980                    Fortify_LeaveScope(); 
     1981#                   endif 
    19661982                  } 
    19671983                } 
    … …  
    20202036      if (li->type != IDM_OPENDEFAULT && li->type != IDM_OPENSETTINGS) 
    20212037      { 
    2022         FreeListInfo(li); 
     2038        FreeListInfo(li); 
    20232039      } 
    20242040    } 
    … …  
    20452061      free(dcd); 
    20462062#     ifdef FORTIFY 
    2047       //Fortify_LeaveScope(); 
    2048 #      endif 
     2063      Fortify_LeaveScope(); 
     2064#     endif 
    20492065      WinSetWindowPtr(dcd->hwndCnr, QWL_USER, NULL); 
    20502066    } 
    … …  
    25922608 
    25932609      if ((INT)mp1 == 5 || (INT)mp1 == 13 || (INT)mp1 == 21) 
    2594         hwnd = StartViewer(HWND_DESKTOP, (INT)mp1, 
    2595                            (CHAR *)mp2, dcd->hwndFrame); 
     2610        hwnd = StartViewer(HWND_DESKTOP, (INT)mp1, 
     2611                           (CHAR *)mp2, dcd->hwndFrame); 
    25962612      else 
    2597         hwnd = StartMLEEditor(dcd->hwndParent, 
    2598                               (INT)mp1, (CHAR *)mp2, dcd->hwndFrame); 
     2613        hwnd = StartMLEEditor(dcd->hwndParent, 
     2614                              (INT)mp1, (CHAR *)mp2, dcd->hwndFrame); 
    25992615      free((CHAR *)mp2); 
    26002616      return MRFROMLONG(hwnd); 
    … …  
    29532969        { 
    29542970          LISTINFO *li; 
    2955 #         ifdef FORTIFY 
    2956           Fortify_EnterScope(); 
    2957 #          endif 
     2971#         ifdef FORTIFY 
     2972          Fortify_EnterScope(); 
     2973#         endif 
    29582974          li = xmallocz(sizeof(LISTINFO), pszSrcFile, __LINE__); 
    29592975          if (li) { 
    … …  
    30153031            case IDM_VIRUSSCAN: 
    30163032            case IDM_OPENDEFAULT: 
    3017             case IDM_OPENSETTINGS: 
    3018             case IDM_MCIPLAY: 
     3033            case IDM_OPENSETTINGS: 
     3034            case IDM_MCIPLAY: 
    30193035              strcpy(li->targetpath, dcd->workdir); 
    30203036              break; 
    … …  
    30313047                UnHilite(hwnd, TRUE, &dcd->lastselection, 0); 
    30323048            } 
    3033             else { 
     3049            else { 
    30343050              free(li); 
    3035 #             ifdef FORTIFY 
    3036               Fortify_LeaveScope(); 
    3037 #              endif 
    3038             } 
    3039           } 
     3051            } 
     3052          } 
     3053#         ifdef FORTIFY 
     3054          Fortify_LeaveScope(); 
     3055#         endif 
    30403056        } 
    30413057        break; 
    … …  
    35093525#     ifdef FORTIFY 
    35103526      Fortify_EnterScope(); 
    3511 #      endif 
     3527#     endif 
    35123528      dcd = xmallocz(sizeof(DIRCNRDATA), pszSrcFile, __LINE__); 
    35133529      if (!dcd) { 
    … …  
    35193535        dcd->id = id; 
    35203536        dcd->type = ARC_FRAME; 
    3521         if (!pTmpDir) { 
    3522           save_dir2(dcd->workdir); 
    3523           if (dcd->workdir[strlen(dcd->workdir) - 1] != '\\') 
    3524             strcat(dcd->workdir, "\\"); 
    3525           sprintf(dcd->workdir + strlen(dcd->workdir), "%s.%03x", 
    3526                   ArcTempRoot, (clock() & 4095)); 
    3527         } 
    3528         else 
    3529           sprintf(dcd->workdir, "%s.%03x", 
    3530                   ArcTempRoot, (clock() & 4095)); 
     3537        if (!pTmpDir) { 
     3538          save_dir2(dcd->workdir); 
     3539          if (dcd->workdir[strlen(dcd->workdir) - 1] != '\\') 
     3540            strcat(dcd->workdir, "\\"); 
     3541          sprintf(dcd->workdir + strlen(dcd->workdir), "%s.%03x", 
     3542                  ArcTempRoot, (clock() & 4095)); 
     3543        } 
     3544        else 
     3545          sprintf(dcd->workdir, "%s.%03x", 
     3546                  ArcTempRoot, (clock() & 4095)); 
    35313547        strcpy(dcd->arcname, fullname); 
    35323548        if (*extractpath) { 
    … …  
    35983614                     IDS_WINCREATEWINDOW); 
    35993615          PostMsg(hwndClient, WM_CLOSE, MPVOID, MPVOID); 
    3600           free(dcd); 
    3601 #         ifdef FORTIFY 
    3602           Fortify_LeaveScope(); 
    3603 #          endif 
     3616          free(dcd); 
    36043617          hwndFrame = (HWND) 0; 
    36053618        } 
    … …  
    36923705        } 
    36933706      } 
     3707#     ifdef FORTIFY 
     3708      Fortify_LeaveScope(); 
     3709#     endif 
    36943710    } 
    36953711  } 
  • trunk/dll/collect.c

    r1065 r1077  
    5050  06 Jul 08 GKY Update delete/undelete to include move to and open XWP trashcan 
    5151  11 Jul 08 JBS Ticket 230: Simplified code and eliminated some local variables by incorporating 
    52                 all the details view settings (both the global variables and those in the 
    53                 DIRCNRDATA struct) into a new struct: DETAILS_SETTINGS. 
     52                all the details view settings (both the global variables and those in the 
     53                DIRCNRDATA struct) into a new struct: DETAILS_SETTINGS. 
    5454 
    5555***********************************************************************/ 
    … …  
    7878#include "tmrsvcs.h"                    // ITIMER_DESC 
    7979#include "notebook.h"                   // CfgDlgProc 
    80 #include "command.h"                    // RunCommand 
     80#include "command.h"                    // RunCommand 
    8181#include "fm3dll.h" 
    8282 
    … …  
    466466  switch (msg) { 
    467467  case WM_CREATE: 
     468    // 18 Jul 08 SHL fixme to doc why messsage gets lost 
     469    DbgMsg(pszSrcFile, __LINE__, "WM_CREATE mp1 %p mp2 %p", mp1, mp2);  // 18 Jul 08 SHL fixme 
    468470    break; 
    469471 
    … …  
    505507 
    506508  case UM_SETUP: 
     509#   ifdef FORTIFY 
     510    Fortify_EnterScope(); 
     511#   endif 
    507512    dcd = WinQueryWindowPtr(hwnd, QWL_USER); 
    508513    if (dcd) { 
     514#     ifdef FORTIFY 
     515      Fortify_ChangeOwner(dcd); 
     516#     endif 
    509517      /* set unique id */ 
    510518      WinSetWindowUShort(hwnd, 
    … …  
    601609            nm = 1; 
    602610            hdir = HDIR_CREATE; 
    603             DosError(FERR_DISABLEHARDERR); 
    604             if (FindCnrRecord(dcd->hwndCnr, 
     611            DosError(FERR_DISABLEHARDERR); 
     612            if (FindCnrRecord(dcd->hwndCnr, 
    605613                              li->list[x], 
    606614                              NULL, 
    607615                              FALSE, 
    608616                              FALSE, 
    609                               TRUE)) { 
    610               pci = UpdateCnrRecord(dcd->hwndCnr, li->list[x], FALSE, dcd); 
    611               if (Filter((PMINIRECORDCORE) pci, (PVOID) & dcd->mask)) { 
    612                 pci->rc.flRecordAttr &= ~CRA_FILTERED; 
    613                 WinSendMsg(dcd->hwndCnr, CM_INVALIDATERECORD, MPVOID, 
    614                            MPFROM2SHORT(0, CMA_REPOSITION | CMA_ERASE)); 
    615               } 
    616               pci = (PCNRITEM) pci->rc.preccNextRecord; 
     617                              TRUE)) { 
     618              pci = UpdateCnrRecord(dcd->hwndCnr, li->list[x], FALSE, dcd); 
     619              if (Filter((PMINIRECORDCORE) pci, (PVOID) & dcd->mask)) { 
     620                pci->rc.flRecordAttr &= ~CRA_FILTERED; 
     621                WinSendMsg(dcd->hwndCnr, CM_INVALIDATERECORD, MPVOID, 
     622                           MPFROM2SHORT(0, CMA_REPOSITION | CMA_ERASE)); 
     623              } 
     624              pci = (PCNRITEM) pci->rc.preccNextRecord; 
    617625              if (pciP) 
    618626                pciP->rc.preccNextRecord = (PMINIRECORDCORE) pci; 
    619627              else 
    620                 pciFirst = pci; 
    621             } 
     628                pciFirst = pci; 
     629            } 
    622630            else if (*li->list[x] && 
    623631                !DosQueryPathInfo(li->list[x], FIL_QUERYFULLNAME, 
    … …  
    631639                               &fb4, sizeof(fb4), &nm, FIL_QUERYEASIZEL)) { 
    632640              DosFindClose(hdir); 
    633               priority_normal(); 
    634                 *fb4.achName = 0; 
    635                 ullTotalBytes = FillInRecordFromFFB(dcd->hwndCnr, 
    636                                                     pci, 
     641              priority_normal(); 
     642                *fb4.achName = 0; 
     643                ullTotalBytes = FillInRecordFromFFB(dcd->hwndCnr, 
     644                                                    pci, 
    637645                                                    fullname, &fb4, FALSE, dcd); 
    638                 dcd->ullTotalBytes += ullTotalBytes; 
    639                 pciP = pci; 
    640                 pci = (PCNRITEM) pci->rc.preccNextRecord; 
     646                dcd->ullTotalBytes += ullTotalBytes; 
     647                pciP = pci; 
     648                pci = (PCNRITEM) pci->rc.preccNextRecord; 
    641649            } 
    642650            else { 
    … …  
    647655                pciP->rc.preccNextRecord = (PMINIRECORDCORE) pci; 
    648656              else 
    649                 pciFirst = pci; 
    650               if (pciT) 
    651                 FreeCnrItemData(pciT); // FreeCnrItem(hwnd, pciT); 
     657                pciFirst = pci; 
     658              if (pciT) 
     659                FreeCnrItemData(pciT); // FreeCnrItem(hwnd, pciT); 
    652660              ulMaxFiles--;             // Remember gone 
    653661            } 
    … …  
    680688  case UM_COLLECTFROMFILE: 
    681689    dcd = WinQueryWindowPtr(hwnd, QWL_USER); 
     690#   ifdef FORTIFY 
     691    Fortify_EnterScope(); 
     692#   endif 
     693 
    682694    if (dcd && mp1) { 
    683695      FILESTATUS4L fs4; 
    … …  
    690702      size_t c; 
    691703 
     704#     ifdef FORTIFY 
     705      Fortify_ChangeOwner(mp1); 
     706#     endif 
     707 
    692708      fp = _fsopen((CHAR *)mp1, "r", SH_DENYNO); 
    693709      if (fp) { 
    … …  
    722738            } 
    723739            /* fullname now contains name of file to collect */ 
    724             DosError(FERR_DISABLEHARDERR); 
    725             if (FindCnrRecord(dcd->hwndCnr, 
     740            DosError(FERR_DISABLEHARDERR); 
     741            if (FindCnrRecord(dcd->hwndCnr, 
    726742                              fullname, 
    727743                              NULL, 
    728744                              FALSE, 
    729745                              FALSE, 
    730                               TRUE)) { 
    731               pci = UpdateCnrRecord(dcd->hwndCnr, fullname, FALSE, dcd); 
    732               if (Filter((PMINIRECORDCORE) pci, (PVOID) & dcd->mask)) { 
    733                 pci->rc.flRecordAttr &= ~CRA_FILTERED; 
    734                 WinSendMsg(dcd->hwndCnr, CM_INVALIDATERECORD, MPVOID, 
    735                            MPFROM2SHORT(0, CMA_REPOSITION | CMA_ERASE)); 
    736               } 
    737               /*pci = (PCNRITEM) pci->rc.preccNextRecord; 
     746                              TRUE)) { 
     747              pci = UpdateCnrRecord(dcd->hwndCnr, fullname, FALSE, dcd); 
     748              if (Filter((PMINIRECORDCORE) pci, (PVOID) & dcd->mask)) { 
     749                pci->rc.flRecordAttr &= ~CRA_FILTERED; 
     750                WinSendMsg(dcd->hwndCnr, CM_INVALIDATERECORD, MPVOID, 
     751                           MPFROM2SHORT(0, CMA_REPOSITION | CMA_ERASE)); 
     752              } 
     753              /*pci = (PCNRITEM) pci->rc.preccNextRecord; 
    738754              if (pciP) 
    739755                pciP->rc.preccNextRecord = (PMINIRECORDCORE) pci; 
    740756              else 
    741                 pciFirst = pci;*/ 
    742             } 
     757                pciFirst = pci;*/ 
     758            } 
    743759            else if (IsFullName(fullname) && 
    744760                !IsRoot(fullname) && 
    … …  
    746762                                  FIL_QUERYEASIZEL, 
    747763                                  &fs4, 
    748                                   sizeof(fs4)))  { 
     764                                  sizeof(fs4))) { 
    749765              /* collect it */ 
    750766              pci = WinSendMsg(dcd->hwndCnr, 
    … …  
    791807#   ifdef FORTIFY 
    792808    Fortify_LeaveScope(); 
    793 #    endif 
     809#   endif 
    794810    return 0; 
    795811 
    … …  
    890906 
    891907  case UM_MASSACTION: 
     908#   ifdef FORTIFY 
     909    Fortify_EnterScope(); 
     910#   endif 
    892911    if (mp1) { 
     912#     ifdef FORTIFY 
     913      Fortify_ChangeOwner(mp1); 
     914#     endif 
    893915      dcd = WinQueryWindowPtr(hwnd, QWL_USER); 
    894916      if (dcd) { 
    895917        WORKER *wk; 
    896 #       ifdef FORTIFY 
    897         Fortify_EnterScope(); 
    898 #        endif 
    899918        wk = xmallocz(sizeof(WORKER), pszSrcFile, __LINE__); 
    900919        if (!wk)Â