Changeset 1077 for trunk/dll/misc.c


Ignore:
Timestamp:
Jul 18, 2008, 8:11:54 PM (17 years ago)
Author:
Steven Levine
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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dll/misc.c

    r1065 r1077  
    4242  29 Feb 08 GKY Use xfree where appropriate
    4343  08 Mar 08 JBS Ticket 230: Replace prefixless INI keys for default directory containers with
    44                 keys using a "DirCnr." prefix
     44                keys using a "DirCnr." prefix
    4545  19 Jun 08 JBS Ticket 239: Fix LoadDetailsSwitches so INI file is read correctly and details
    46                 switches are set correctly.
     46                switches are set correctly.
    4747  11 Jul 08 JBS Ticket 230: Simplified code and eliminated some local variables by incorporating
    48                 all the details view settings (both the global variables and those in the
    49                 DIRCNRDATA struct) into a new struct: DETAILS_SETTINGS.
     48                all the details view settings (both the global variables and those in the
     49                DIRCNRDATA struct) into a new struct: DETAILS_SETTINGS.
     50  17 Jul 08 SHL Add GetTidForWindow for Fortify support
    5051
    5152***********************************************************************/
     
    5556#include <ctype.h>
    5657#include <share.h>
    57 #include <malloc.h>                  // _heapmin
     58#include <malloc.h>                     // _heapmin
    5859
    5960#define INCL_DOS
     
    6465#include "fm3dlg.h"
    6566#include "fm3str.h"
    66 #include "pathutil.h"               // BldQuotedFileName
    67 #include "errutil.h"                // Dos_Error...
    68 #include "strutil.h"                // GetPString
    69 #include "command.h"                // LINKCMDS
     67#include "pathutil.h"                   // BldQuotedFileName
     68#include "errutil.h"                    // Dos_Error...
     69#include "strutil.h"                    // GetPString
     70#include "command.h"                    // LINKCMDS
    7071#include "fm3dll.h"
     72#include "misc.h"
    7173#include "fortify.h"
    7274
     
    112114    return yes;
    113115}
     116
     117#ifdef FORTIFY
     118
     119/**
     120 * Return tid for fm/2 window
     121 * window must exist and must be created by fm/2
     122 * @param hwnd is window handle
     123 * @returns tid or -1 if error
     124 */
     125
     126INT GetTidForWindow(HWND hwnd)
     127{
     128    PIB *ppib;
     129    TIB *ptib;
     130    LONG tid = -1;
     131    APIRET rc = DosGetInfoBlocks(&ptib, &ppib);
     132
     133    if (rc) {
     134      Dos_Error(MB_CANCEL, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
     135                "DosGetInfoBlocks");
     136    }
     137    else {
     138      PID pid;
     139      TID tid;
     140      if (!WinQueryWindowProcess(hwnd, &pid, &tid))
     141        Win_Error(hwnd, HWND_DESKTOP, pszSrcFile, __LINE__, "WinQueryWindowProcess failed for %X", hwnd);
     142      else if (pid != ppib->pib_ulpid)
     143        Runtime_Error(pszSrcFile, __LINE__, "hwnd %X not created by fm/2", hwnd);
     144      else
     145        tid = ptib->tib_ptib2->tib2_ultid;
     146    }
     147    return tid;
     148}
     149
     150#endif // FORTIFY
    114151
    115152VOID SetShiftState(VOID)
     
    710747          USHORT len;
    711748          CHAR *eaval;
    712           LONG retlen;
    713           PSZ psz;
     749          LONG retlen;
     750          PSZ psz;
    714751
    715752          retlen = WinQueryWindowText(hwndMLE, sizeof(szSubject), szSubject);
    716753          szSubject[retlen + 1] = 0;
    717           bstrip(szSubject);
    718           if (pci->pszSubject != NullStr) {
    719             if (retlen == 0) {
    720               psz = pci->pszSubject;
    721               pci->pszSubject = NullStr;
    722               xfree(psz, pszSrcFile, __LINE__);
    723             }
    724             else
    725               pci->pszSubject = xrealloc(pci->pszSubject, retlen + 1, pszSrcFile, __LINE__);
    726           }
    727           else {
    728             pci->pszSubject = xmalloc(retlen + 1, pszSrcFile, __LINE__);
    729             if (!pci->pszSubject)
    730               return FALSE;
    731           }
     754          bstrip(szSubject);
     755          if (pci->pszSubject != NullStr) {
     756            if (retlen == 0) {
     757              psz = pci->pszSubject;
     758              pci->pszSubject = NullStr;
     759              xfree(psz, pszSrcFile, __LINE__);
     760            }
     761            else
     762              pci->pszSubject = xrealloc(pci->pszSubject, retlen + 1, pszSrcFile, __LINE__);
     763          }
     764          else {
     765            pci->pszSubject = xmalloc(retlen + 1, pszSrcFile, __LINE__);
     766            if (!pci->pszSubject)
     767              return FALSE;
     768          }
    732769          len = strlen(szSubject);
    733770          if (len)
     
    772809
    773810          CHAR longname[CCHMAXPATHCOMP];
    774           LONG retlen;
    775           PSZ psz;
     811          LONG retlen;
     812          PSZ psz;
    776813
    777814          *longname = 0;
    778815          retlen = WinQueryWindowText(hwndMLE, sizeof(longname), longname);
    779816          longname[retlen + 1] = 0;
    780           chop_at_crnl(longname);
    781           bstrip(longname);
    782           WinSetWindowText(hwndMLE, longname);
    783           if (pci->pszLongName != NullStr) {
    784             if (retlen == 0) {
    785               psz = pci->pszLongName;
    786               pci->pszLongName = NullStr;
    787               xfree(psz, pszSrcFile, __LINE__);
    788             }
    789             else
    790               pci->pszLongName = xrealloc(pci->pszLongName, retlen + 1, pszSrcFile, __LINE__);
    791           }
    792           else {
    793             pci->pszLongName = xmalloc(retlen + 1, pszSrcFile, __LINE__);
    794             if (!pci->pszLongName)
    795               return FALSE;
    796           }
     817          chop_at_crnl(longname);
     818          bstrip(longname);
     819          WinSetWindowText(hwndMLE, longname);
     820          if (pci->pszLongName != NullStr) {
     821            if (retlen == 0) {
     822              psz = pci->pszLongName;
     823              pci->pszLongName = NullStr;
     824              xfree(psz, pszSrcFile, __LINE__);
     825            }
     826            else
     827              pci->pszLongName = xrealloc(pci->pszLongName, retlen + 1, pszSrcFile, __LINE__);
     828          }
     829          else {
     830            pci->pszLongName = xmalloc(retlen + 1, pszSrcFile, __LINE__);
     831            if (!pci->pszLongName)
     832              return FALSE;
     833          }
    797834          return (MRESULT) WriteLongName(pci->pszFileName, longname);
    798835        }
     
    9801017    *ex.environment = 0;
    9811018    ret = WinDlgBox(HWND_DESKTOP, hwnd, CmdLineDlgProc, FM3ModHandle,
    982                     EXEC_FRAME, &ex);
     1019                    EXEC_FRAME, &ex);
    9831020    if (ret == 1) {
    9841021      lastflags = ex.flags;
    9851022      return runemf2(ex.flags, hwnd, pszSrcFile, __LINE__, path,
    986                      *ex.environment ? ex.environment : NULL,
    987                      "%s", pszCmdLine) != -1;
     1023                     *ex.environment ? ex.environment : NULL,
     1024                     "%s", pszCmdLine) != -1;
    9881025    }
    9891026    else if (ret != 0)
     
    21572194#pragma alloc_text(MISC1,BoxWindow,PaintRecessedWindow,PostMsg,PaintSTextWindow,IsFm2Window)
    21582195#pragma alloc_text(MISC1,FixSwitchList,FindDirCnr,CurrentRecord,SetShiftState,AddToListboxBottom)
     2196
     2197#ifdef FORTIFY
     2198#pragma alloc_text(MISC1,GetTidForWindow)
     2199#endif // FORTIFY
     2200
    21592201#pragma alloc_text(CNR_MISC1,AdjustCnrColVis,AdjustCnrColsForFSType)
    21602202#pragma alloc_text(CNR_MISC1,AdjustCnrColsForPref,SetCnrCols)
Note: See TracChangeset for help on using the changeset viewer.