Changeset 21435 for trunk/src/kernel32


Ignore:
Timestamp:
Aug 30, 2010, 2:05:13 PM (15 years ago)
Author:
dmik
Message:

kernel32: Return FALSE and set ERROR_CALL_NOT_IMPLEMENTED in HeapWalk() to prevent applications using this API to walk the heap from looping forever.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/heap.cpp

    r21361 r21435  
    3737{
    3838  HANDLE _processheap;
    39  
     39
    4040  //SvL: Only one process heap per process
    4141  OS2ProcessHeap = new OS2Heap(HEAP_GENERATE_EXCEPTIONS, 0x4000, 0);
     
    4444    return(NULL);
    4545  _processheap = OS2ProcessHeap->getHeapHandle();
    46  
     46
    4747  return _processheap;
    4848}
     
    7070  else                               \
    7171    curheap = OS2Heap::find(hHeap);  \
    72  
    73 
    74 
    75 //******************************************************************************
    76 //******************************************************************************
    77 LPVOID WIN32API HeapAlloc(HANDLE hHeap, 
     72
     73
     74
     75//******************************************************************************
     76//******************************************************************************
     77LPVOID WIN32API HeapAlloc(HANDLE hHeap,
    7878                          DWORD dwFlags,
    7979                          DWORD dwBytes)
     
    9191//******************************************************************************
    9292//******************************************************************************
    93 LPVOID HeapReAlloc(HANDLE hHeap, 
     93LPVOID HeapReAlloc(HANDLE hHeap,
    9494                   DWORD dwFlags,
    95                    LPVOID lpMem, 
     95                   LPVOID lpMem,
    9696                   DWORD dwBytes)
    9797{
     
    110110//******************************************************************************
    111111//******************************************************************************
    112 BOOL WIN32API HeapFree(HANDLE hHeap, 
     112BOOL WIN32API HeapFree(HANDLE hHeap,
    113113                       DWORD dwFlags,
    114114                       LPVOID lpMem)
     
    121121
    122122  BOOL fResult = curheap->Free(dwFlags, lpMem);
    123  
     123
    124124  /* 2002-04-25 PH
    125125   * Apparently, Win2k does not do this. It does not touch last error,
    126126   * it does not even return FALSE but just anything != TRUE.
    127127   *
    128    
     128
    129129  if (fResult == FALSE)
    130130    SetLastError(ERROR_INVALID_HANDLE);
    131  
     131
    132132  */
    133  
     133
    134134  return fResult;
    135135}
    136136//******************************************************************************
    137137//******************************************************************************
    138 HANDLE WIN32API HeapCreate(DWORD flOptions, DWORD dwInitialSize, 
     138HANDLE WIN32API HeapCreate(DWORD flOptions, DWORD dwInitialSize,
    139139                           DWORD dwMaximumSize)
    140140{
     
    219219BOOL WIN32API HeapWalk(HANDLE hHeap, LPVOID lpEntry)
    220220{
    221   dprintf(("KERNEL32:  HeapWalk - stub (TRUE)\n"));
    222   return(TRUE);
     221  dprintf(("KERNEL32:  HeapWalk - stub (FALSE, ERROR_CALL_NOT_IMPLEMENTED)\n"));
     222  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
     223  return(FALSE);
    223224}
    224225//******************************************************************************
     
    232233 * Win32 Global heap functions (GlobalXXX).
    233234 * These functions included in Win32 for compatibility with 16 bit Windows
    234  * Especially the moveable blocks and handles are oldish. 
     235 * Especially the moveable blocks and handles are oldish.
    235236 * But the ability to directly allocate memory with GPTR and LPTR is widely
    236237 * used.
    237238 *
    238239 * The handle stuff looks horrible, but it's implemented almost like Win95
    239  * does it. 
     240 * does it.
    240241 *
    241242 */
     
    280281   else
    281282      hpflags=0;
    282    
     283
    283284   if((flags & GMEM_MOVEABLE)==0) /* POINTER */
    284285   {
     
    308309      pintern->Flags=flags>>8;
    309310      pintern->LockCount=0;
    310      
     311
    311312      /* HeapUnlock(heap); */
    312        
     313
    313314      return INTERN_TO_HANDLE(pintern);
    314315   }
     
    340341
    341342   /* HeapLock(GETPROCESSHEAP); */
    342    
     343
    343344   pintern=HANDLE_TO_INTERN(hmem);
    344345   if(pintern->Magic==MAGIC_GLOBAL_USED)
     
    384385   /* HeapLock(GETPROCESSHEAP); */
    385386   pintern=HANDLE_TO_INTERN(hmem);
    386    
     387
    387388   if(pintern->Magic==MAGIC_GLOBAL_USED)
    388389   {
     
    616617   PGLOBAL32_INTERN pintern;
    617618   HGLOBAL        hreturned = 0;
    618  
     619
    619620  // 2001-10-17 PH
    620621  // Note: we do have a *HANDLE* here still ...
     
    630631   }
    631632#endif
    632  
     633
    633634   if(ISPOINTER(hmem)) /* POINTER */
    634635   {
     
    642643      /* HeapLock(heap); */
    643644      pintern=HANDLE_TO_INTERN(hmem);
    644      
     645
    645646      if(pintern->Magic==MAGIC_GLOBAL_USED)
    646       { 
     647      {
    647648
    648649/* WIN98 does not make this test. That is you can free a */
     
    656657         if(!HeapFree(GETPROCESSHEAP, 0, pintern))
    657658            hreturned=hmem;
    658       }     
     659      }
    659660      else
    660661      {
     
    663664        hreturned = hmem;
    664665      }
    665      
     666
    666667      /* HeapUnlock(heap); */
    667668   }
    668  
     669
    669670   return hreturned;
    670671}
     
    682683   PGLOBAL32_INTERN     pintern;
    683684
    684    if(ISPOINTER(hmem)) 
     685   if(ISPOINTER(hmem))
    685686   {
    686687      retval=HeapSize(GETPROCESSHEAP, 0,  (LPVOID) hmem);
     
    690691      /* HeapLock(heap); */
    691692      pintern=HANDLE_TO_INTERN(hmem);
    692      
     693
    693694      if(pintern->Magic==MAGIC_GLOBAL_USED)
    694695      {
     
    775776      pintern=HANDLE_TO_INTERN(hmem);
    776777      if(pintern->Magic==MAGIC_GLOBAL_USED)
    777       {               
     778      {
    778779         retval=pintern->LockCount + (pintern->Flags<<8);
    779780         if(pintern->Pointer==0)
Note: See TracChangeset for help on using the changeset viewer.