Changeset 1078
- Timestamp:
- 07/19/08 06:08:02 (6 weeks ago)
- Location:
- trunk
- Files:
-
- 17 modified
-
dll/arccnrs.c (modified) (1 diff)
-
dll/autoview.c (modified) (6 diffs)
-
dll/collect.c (modified) (5 diffs)
-
dll/command.c (modified) (3 diffs)
-
dll/dircnrs.c (modified) (5 diffs)
-
dll/filldir.c (modified) (4 diffs)
-
dll/fm3dll.def (modified) (2 diffs)
-
dll/fortify.c (modified) (68 diffs)
-
dll/fortify.h (modified) (3 diffs)
-
dll/makelist.c (modified) (1 diff)
-
dll/misc.c (modified) (3 diffs)
-
dll/misc.h (modified) (1 diff)
-
dll/objwin.c (modified) (2 diffs)
-
dll/treecnr.c (modified) (2 diffs)
-
dll/walkem.c (modified) (6 diffs)
-
dll/worker.c (modified) (1 diff)
-
fm3.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/dll/arccnrs.c
r1077 r1078 1361 1361 else { 1362 1362 # ifdef FORTIFY 1363 Fortify_ ChangeOwner(dcd);1363 Fortify_BecomeOwner(dcd); 1364 1364 # endif 1365 1365 /* set unique id */ -
trunk/dll/autoview.c
r1063 r1078 477 477 (pffbFile->achName[1] == '.' && 478 478 !pffbFile->achName[2]))))) { 479 CommaFmtULL(szCmmaFmtFileSize,480 sizeof(szCmmaFmtFileSize),481 pffbFile->cbFile + CBLIST_TO_EASIZE(pffbFile->cbList),482 ' ');479 CommaFmtULL(szCmmaFmtFileSize, 480 sizeof(szCmmaFmtFileSize), 481 pffbFile->cbFile + CBLIST_TO_EASIZE(pffbFile->cbList), 482 ' '); 483 483 sprintf(p, 484 484 "%s%-*.*s %-8s [%s%s%s%s] %04lu/%02lu/%02lu " … … 487 487 ml, 488 488 ml, 489 pffbFile->achName,490 szCmmaFmtFileSize,489 pffbFile->achName, 490 szCmmaFmtFileSize, 491 491 pffbFile->attrFile & FILE_READONLY ? "R" : "-", 492 492 pffbFile->attrFile & FILE_ARCHIVED ? "A" : "-", … … 640 640 # ifdef FORTIFY 641 641 Fortify_EnterScope(); 642 # endif642 # endif 643 643 hmq2 = WinCreateMsgQueue(hab2, 128); 644 644 if (hmq2) { … … 675 675 # ifdef FORTIFY 676 676 Fortify_LeaveScope(); 677 # endif677 # endif 678 678 } 679 679 } … … 800 800 free(ea); 801 801 # ifdef FORTIFY 802 Fortify_LeaveScope();802 Fortify_LeaveScope(); 803 803 # endif 804 804 } … … 853 853 free(cf); 854 854 # ifdef FORTIFY 855 Fortify_LeaveScope();855 Fortify_LeaveScope(); 856 856 # endif 857 857 } -
trunk/dll/collect.c
r1077 r1078 513 513 if (dcd) { 514 514 # ifdef FORTIFY 515 Fortify_ ChangeOwner(dcd);515 Fortify_BecomeOwner(dcd); 516 516 # endif 517 517 /* set unique id */ … … 703 703 704 704 # ifdef FORTIFY 705 Fortify_ ChangeOwner(mp1);705 Fortify_BecomeOwner(mp1); 706 706 # endif 707 707 … … 911 911 if (mp1) { 912 912 # ifdef FORTIFY 913 Fortify_ ChangeOwner(mp1);913 Fortify_BecomeOwner(mp1); 914 914 # endif 915 915 dcd = WinQueryWindowPtr(hwnd, QWL_USER); … … 948 948 if (mp1) { 949 949 # ifdef FORTIFY 950 Fortify_ ChangeOwner(mp1);950 Fortify_BecomeOwner(mp1); 951 951 # endif 952 952 dcd = WinQueryWindowPtr(hwnd, QWL_USER); … … 1496 1496 # ifdef FORTIFY 1497 1497 Fortify_EnterScope(); 1498 Fortify_ ChangeOwner(mp1);1498 Fortify_BecomeOwner(mp1); 1499 1499 # endif 1500 1500 if (!dcd) -
trunk/dll/command.c
r1039 r1078 24 24 29 Feb 08 GKY Changes to enable user settable command line length 25 25 29 Feb 08 GKY Use xfree where appropriate 26 18 Jul 08 SHL Add Fortify support 26 27 27 28 ***********************************************************************/ … … 355 356 info = xmallocz(sizeof(LINKCMDS), pszSrcFile, __LINE__); 356 357 if (info) { 358 # ifdef FORTIFY 359 Fortify_SetOwner(info, 1); 360 Fortify_SetScope(info, 1); 361 # endif 357 362 info->pszCmdLine = xstrdup(pszCmdLine, pszSrcFile, __LINE__); 358 363 info->title = xstrdup(title, pszSrcFile, __LINE__); … … 364 369 break; 365 370 } 371 # ifdef FORTIFY 372 Fortify_SetOwner(info->pszCmdLine, 1); 373 Fortify_SetScope(info->pszCmdLine, 1); 374 Fortify_SetOwner(info->title, 1); 375 Fortify_SetScope(info->title, 1); 376 # endif 366 377 if (!cmdhead) 367 378 cmdhead = info; -
trunk/dll/dircnrs.c
r1077 r1078 646 646 if (dcd) { 647 647 # ifdef FORTIFY 648 Fortify_ ChangeOwner(dcd);648 Fortify_BecomeOwner(dcd); // We free dcd 649 649 # endif 650 650 /* set unique id */ … … 1065 1065 1066 1066 case WM_DESTROY: 1067 # ifdef FORTIFY 1068 DbgMsg(pszSrcFile, __LINE__, "WM_DESTROY hwnd %p", hwnd); // 18 Jul 08 SHL fixme 1069 # endif 1067 1070 dcd = WinQueryWindowPtr(hwnd, QWL_USER); 1068 1071 if (dcd) { … … 1079 1082 # ifdef FORTIFY 1080 1083 Fortify_LeaveScope(); 1081 # endif1084 # endif 1082 1085 WinSetWindowPtr(dcd->hwndCnr, QWL_USER, NULL); 1083 1086 DosPostEventSem(CompactSem); … … 3408 3411 3409 3412 case WM_DESTROY: 3413 # ifdef FORTIFY 3414 DbgMsg(pszSrcFile, __LINE__, "WM_DESTROY hwnd %p", hwnd); // 18 Jul 08 SHL fixme 3415 # endif 3410 3416 if (DirMenu) 3411 3417 WinDestroyWindow(DirMenu); … … 3542 3548 } 3543 3549 else { 3550 # ifdef FORTIFY 3551 Fortify_ChangeScope(dcd, -1); 3552 # endif 3544 3553 RestorePresParams(dcd->hwndCnr, "DirCnr"); 3545 3554 WinSetWindowPtr(dcd->hwndCnr, QWL_USER, (PVOID) dcd); -
trunk/dll/filldir.c
r1077 r1078 63 63 #include "errutil.h" // Dos_Error... 64 64 #include "strutil.h" // GetPString 65 #include "misc.h" // GetTidForWindow 66 #include "fortify.h" // 06 May 08 SHL 65 67 #include "fm3dll.h" 66 67 #include "fortify.h" // 06 May 08 SHL68 68 69 69 static PSZ pszSrcFile = __FILE__; … … 262 262 c2++; 263 263 pci->pszFileName = xmalloc(c + c2, pszSrcFile, __LINE__); 264 # ifdef FORTIFY 265 { 266 unsigned tid = GetTidForWindow(hwndCnr); 267 // char buf[256]; 268 if (tid == 1) 269 Fortify_ChangeScope(pci->pszFileName, -1); 270 else 271 Fortify_SetOwner(pci->pszFileName, 1); 272 // sprintf(buf, "Owner forced to %u", GetTidForWindow(hwndCnr)); 273 // Fortify_LabelPointer(pci->pszFmtFileSize, buf); 274 } 275 # endif 264 276 memcpy(pci->pszFileName, pszDirectory, c + 1); 265 277 p = pci->pszFileName + c - 1; … … 353 365 value = pfea->szName + pfea->cbName + 1; 354 366 value[pfea->cbValue] = 0; 355 if (*(USHORT *) value == EAT_ASCII) 367 if (*(USHORT *) value == EAT_ASCII) { 356 368 pci->pszLongName = xstrdup(value + (sizeof(USHORT) * 2), pszSrcFile, __LINE__); 369 # ifdef FORTIFY 370 { 371 unsigned tid = GetTidForWindow(hwndCnr); 372 // char buf[256]; 373 if (tid == 1) 374 Fortify_ChangeScope(pci->pszLongName, -1); 375 else 376 Fortify_SetOwner(pci->pszLongName, 1); 377 // sprintf(buf, "Owner forced to %u", GetTidForWindow(hwndCnr)); 378 // Fortify_LabelPointer(pci->pszFmtFileSize, buf); 379 } 380 # endif 381 } 357 382 } 358 383 free(pfealist); … … 428 453 //comma format the file size for large file support 429 454 { 430 CHAR szBuf[30];455 CHAR szBuf[30]; 431 456 CommaFmtULL(szBuf, sizeof(szBuf), pffb->cbFile, ' '); 432 457 pci->pszFmtFileSize = xstrdup(szBuf, pszSrcFile, __LINE__); 458 # ifdef FORTIFY 459 { 460 unsigned tid = GetTidForWindow(hwndCnr); 461 // char buf[256]; 462 if (tid == 1) 463 Fortify_ChangeScope(pci->pszFmtFileSize, -1); 464 else 465 Fortify_SetOwner(pci->pszFmtFileSize, 1); 466 // sprintf(buf, "Owner forced to %u", GetTidForWindow(hwndCnr)); 467 // Fortify_LabelPointer(pci->pszFmtFileSize, buf); 468 } 469 # endif 433 470 } 434 471 -
trunk/dll/fm3dll.def
r1057 r1078 4 4 5 5 # 14 Jun 07 SHL Convert to OpenWatcom 6 # 18 Jul 08 SHL Add Runtime_Error 6 7 7 8 option description '@#SLAInc:3.11#@##1## 07/08/2008 03:11:00 GKYBuild::EN:US:0:U:@@FM/2 Runtime DLL Copyright (c) 1993, 1998 M. Kimes Copyright (c) 2001, 2008 Steven Levine and Associates, Inc.' … … 288 289 xDosFindNext_ .270, 289 290 xfree_ .271, 290 xmalloc_ .272 291 291 xmalloc_ .272, 292 Runtime_Error_ .273 293 -
trunk/dll/fortify.c
r1077 r1078 2 2 /* $Id$ */ 3 3 /* fortify.cxx - A fortified memory allocation shell - V2.2 */ 4 /* vim: tabs 4 */ 4 5 5 6 /* … … 42 43 43 44 /* 06 May 08 SHL Rework scope logic to be MT capable 44 26 May 08 SHL Show TID for leaking scope 45 17 Jul 08 SHL Add Fortify_SetOwner Fortify_ChangeOwner Fortify_ChangeScope 46 18 Jul 08 SHL Add FORTIFY_VERBOSE_SCOPE_ENTER_EXIT 45 26 May 08 SHL Show TID for leaking scope 46 17 Jul 08 SHL Add Fortify_PresetOwner Fortify_BecomeOwner Fortify_ChangeScope 47 18 Jul 08 SHL Add FORTIFY_VERBOSE_SCOPE_ENTER_EXIT 48 18 Jul 08 SHL Add Fortify_SetScope 49 18 Jul 08 SHL Rename Fortify_ChangeOwner to Fortify_BecomeOwner 50 18 Jul 08 SHL Add reworked Fortify_SetOwner 47 51 */ 48 52 … … 89 93 struct Header 90 94 { 91 unsigned short Checksum; /* For the integrity of our goodies */92 const char *File; /* The sourcefile of the allocator */93 unsigned long Line; /* The sourceline of the allocator */94 # ifdef FORTIFY_TRACK_DEALLOCATED_MEMORY95 const char *FreedFile; /* The sourcefile of the deallocator */96 unsigned long FreedLine; /* The sourceline of the deallocator */97 unsigned char Deallocator; /* The deallocator used */98 # endif99 size_t Size; /* The size of the malloc'd block */100 struct Header *Prev; /* Previous link */101 struct Header *Next; /* Next link */102 char *Label; /* User's Label (may be null) */103 unsigned char Scope; /* Scope level of the owner */104 unsigned char Allocator; /* malloc/realloc/new/etc */105 # ifdef MT_SCOPES106 unsigned short Owner; /* TID ordinal of block owner */107 # endif95 unsigned short Checksum; /* For the integrity of our goodies */ 96 const char *File; /* The sourcefile of the allocator */ 97 unsigned long Line; /* The sourceline of the allocator */ 98 # ifdef FORTIFY_TRACK_DEALLOCATED_MEMORY 99 const char *FreedFile; /* The sourcefile of the deallocator */ 100 unsigned long FreedLine; /* The sourceline of the deallocator */ 101 unsigned char Deallocator; /* The deallocator used */ 102 # endif 103 size_t Size; /* The size of the malloc'd block */ 104 struct Header *Prev; /* Previous link */ 105 struct Header *Next; /* Next link */ 106 char *Label; /* User's Label (may be null) */ 107 unsigned char Scope; /* Scope level of the owner */ 108 unsigned char Allocator; /* malloc/realloc/new/etc */ 109 # ifdef MT_SCOPES 110 unsigned short Owner; /* TID ordinal of block owner */ 111 # endif 108 112 }; 109 113 … … 153 157 #ifdef FORTIFY_TRACK_DEALLOCATED_MEMORY 154 158 #ifdef FORTIFY_WARN_WHEN_DISCARDING_DEALLOCATED_MEMORY 159 155 160 #ifdef FORTIFY_VERBOSE_WARN_WHEN_DISCARDING_DEALLOCATED_MEMORY 156 static const char *st_DeallocatedMemoryBlockString(struct Header *h);161 static const char *st_DeallocatedMemoryBlockString(struct Header *h); 157 162 #endif /* FORTIFY_WARN_WHEN_DISCARDING_DEALLOCATED_MEMORY */ 163 158 164 #endif /* FORTIFY_VERBOSE_WARN_WHEN_DISCARDING_DEALLOCATED_MEMORY */ 159 static int st_IsOnDeallocatedList(struct Header *h);160 static int st_PurgeDeallocatedBlocks(unsigned long Bytes, const char *file, unsigned long line);161 static int st_PurgeDeallocatedScope(unsigned char Scope, const char *file, unsigned long line);162 static int st_CheckDeallocatedBlock(struct Header *h, const char *file, unsigned long line);163 static void st_FreeDeallocatedBlock(struct Header *h, const char *file, unsigned long line);165 static int st_IsOnDeallocatedList(struct Header *h); 166 static int st_PurgeDeallocatedBlocks(unsigned long Bytes, const char *file, unsigned long line); 167 static int st_PurgeDeallocatedScope(unsigned char Scope, const char *file, unsigned long line); 168 static int st_CheckDeallocatedBlock(struct Header *h, const char *file, unsigned long line); 169 static void st_FreeDeallocatedBlock(struct Header *h, const char *file, unsigned long line); 164 170 #endif /* FORTIFY_TRACK_DEALLOCATED_MEMORY */ 165 171 … … 176 182 static const char *st_LastVerifiedFile = "unknown"; 177 183 static unsigned long st_LastVerifiedLine; 184 178 185 #ifdef MT_SCOPES 179 186 static unsigned volatile st_cOrdinals; // Number of known threads … … 183 190 static unsigned char st_Scope = 0; 184 191 #endif 192 185 193 static unsigned char st_Disabled = 0; 186 194 187 195 #ifdef __cplusplus 188 int FORTIFY_STORAGE gbl_FortifyMagic = 0; // 28 Jan 08 SHL189 static const char *st_DeleteFile[FORTIFY_DELETE_STACK_SIZE];190 static unsigned long st_DeleteLine[FORTIFY_DELETE_STACK_SIZE];191 static unsigned long st_DeleteStackTop;196 int FORTIFY_STORAGE gbl_FortifyMagic = 0; // 28 Jan 08 SHL 197 static const char *st_DeleteFile[FORTIFY_DELETE_STACK_SIZE]; 198 static unsigned long st_DeleteLine[FORTIFY_DELETE_STACK_SIZE]; 199 static unsigned long st_DeleteStackTop; 192 200 #endif /* __cplusplus */ 193 201 … … 203 211 204 212 #ifdef FORTIFY_TRACK_DEALLOCATED_MEMORY 205 static struct Header *st_DeallocatedHead = 0;206 static struct Header *st_DeallocatedTail = 0;207 static unsigned long st_TotalDeallocated = 0;213 static struct Header *st_DeallocatedHead = 0; 214 static struct Header *st_DeallocatedTail = 0; 215 static unsigned long st_TotalDeallocated = 0; 208 216 #endif 209 217 … … 212 220 static const char *st_AllocatorName[] = 213 221 { 214 "malloc()",215 "calloc()",216 "realloc()",217 "strdup()",218 "new",219 "new[]"222 "malloc()", 223 "calloc()", 224 "realloc()", 225 "strdup()", 226 "new", 227 "new[]" 220 228 }; 221 229 … … 223 231 static const char *st_DeallocatorName[] = 224 232 { 225 "nobody",226 "free()",227 "realloc()",228 "delete",229 "delete[]"233 "nobody", 234 "free()", 235 "realloc()", 236 "delete", 237 "delete[]" 230 238 }; 231 239 232 240 static const unsigned char st_ValidDeallocator[] = 233 241 { 234 (1<<Fortify_Deallocator_free) | (1<<Fortify_Deallocator_realloc),235 (1<<Fortify_Deallocator_free) | (1<<Fortify_Deallocator_realloc),236 (1<<Fortify_Deallocator_free) | (1<<Fortify_Deallocator_realloc),237 (1<<Fortify_Deallocator_free) | (1<<Fortify_Deallocator_realloc),242 (1<<Fortify_Deallocator_free) | (1<<Fortify_Deallocator_realloc), 243 (1<<Fortify_Deallocator_free) | (1<<Fortify_Deallocator_realloc), 244 (1<<Fortify_Deallocator_free) | (1<<Fortify_Deallocator_realloc), 245 (1<<Fortify_Deallocator_free) | (1<<Fortify_Deallocator_realloc), 238 246 #if defined(FORTIFY_PROVIDE_ARRAY_NEW) && defined(FORTIFY_PROVIDE_ARRAY_DELETE) 239 (1<<Fortify_Deallocator_delete),240 (1<<Fortify_Deallocator_array_delete)247 (1<<Fortify_Deallocator_delete), 248 (1<<Fortify_Deallocator_array_delete) 241 249 #else 242 (1<<Fortify_Deallocator_delete) | (1<<Fortify_Deallocator_array_delete),243 (1<<Fortify_Deallocator_delete) | (1<<Fortify_Deallocator_array_delete)250 (1<<Fortify_Deallocator_delete) | (1<<Fortify_Deallocator_array_delete), 251 (1<<Fortify_Deallocator_delete) | (1<<Fortify_Deallocator_array_delete) 244 252 #endif 245 253 }; … … 252 260 Fortify_Allocate(size_t size, unsigned char allocator, const char *file, unsigned long line) 253 261 { 254 unsigned char *ptr;255 struct Header *h;256 int another_try;262 unsigned char *ptr; 263 struct Header *h; 264 int another_try; 257 265 258 266 #ifdef MT_SCOPES 259 unsigned ordinal;267 unsigned ordinal; 260 268 #endif 261 269 262 /*263 * If Fortify has been disabled, then it's easy264 */265 if(st_Disabled)266 {267 # ifdef FORTIFY_FAIL_ON_ZERO_MALLOC268 if(size == 0 && (allocator == Fortify_Allocator_new269 || allocator == Fortify_Allocator_array_new))270 /* 271 * If Fortify has been disabled, then it's easy 272 */ 273 if(st_Disabled) 274 { 275 # ifdef FORTIFY_FAIL_ON_ZERO_MALLOC 276 if(size == 0 && (allocator == Fortify_Allocator_new 277 || allocator == Fortify_Allocator_array_new)) 270 278 { 271 279 /* 272 280 * A new of zero bytes must succeed, but a malloc of 273 * zero bytes probably won't274 */281 * zero bytes probably won't 282 */ 275 283 return malloc(1); 276 284 } 285 # endif 286 287 return malloc(size); 288 } 289 290 #ifdef FORTIFY_CHECK_ALL_MEMORY_ON_ALLOCATE 291 Fortify_CheckAllMemory(file, line); 277 292 #endif 278 293 279 return malloc(size); 280 } 281 282 #ifdef FORTIFY_CHECK_ALL_MEMORY_ON_ALLOCATE 283 Fortify_CheckAllMemory(file, line); 284 #endif 285 286 if(st_AllocateFailRate > 0) 287 { 288 if(rand() % 100 < st_AllocateFailRate) 289 { 290 #ifdef FORTIFY_WARN_ON_FALSE_FAIL 291 sprintf(st_Buffer, 292 "\nFortify: A \"%s\" of %lu bytes \"false failed\" at %s.%lu\n", 293 st_AllocatorName[allocator], (unsigned long)size, file, line); 294 st_Output(st_Buffer); 295 #endif 296 return(0); 297 } 298 } 299 300 /* Check to see if this allocation will 301 * push us over the artificial limit 302 */ 303 if(st_CurAllocation + size > st_AllocationLimit) 304 { 305 #ifdef FORTIFY_WARN_ON_FALSE_FAIL 306 sprintf(st_Buffer, 307 "\nFortify: A \"%s\" of %lu bytes \"false failed\" at %s.%lu\n", 308 st_AllocatorName[allocator], (unsigned long)size, file, line); 309 st_Output(st_Buffer); 310 #endif 311 return(0); 312 } 294 if(st_AllocateFailRate > 0) 295 { 296 if(rand() % 100 < st_AllocateFailRate) 297 { 298 # ifdef FORTIFY_WARN_ON_FALSE_FAIL 299 sprintf(st_Buffer, 300 "\nFortify: A \"%s\" of %lu bytes \"false failed\" at %s.%lu\n", 301 st_AllocatorName[allocator], (unsigned long)size, file, line); 302 st_Output(st_Buffer); 303 # endif 304 return(0); 305 } 306 } 307 308 /* Check to see if this allocation will 309 * push us over the artificial limit 310 */ 311 if(st_CurAllocation + size > st_AllocationLimit) 312 { 313 # ifdef FORTIFY_WARN_ON_FALSE_FAIL 314 sprintf(st_Buffer, 315 "\nFortify: A \"%s\" of %lu bytes \"false failed\" at %s.%lu\n", 316 st_AllocatorName[allocator], (unsigned long)size, file, line); 317 st_Output(st_Buffer); 318 # endif 319 return(0); 320 } 313 321 314 322 #ifdef FORTIFY_WARN_ON_ZERO_MALLOC 315 323 if(size == 0 && (allocator == Fortify_Allocator_malloc || 316 allocator == Fortify_Allocator_calloc ||317 allocator == Fortify_Allocator_realloc ))324 allocator == Fortify_Allocator_calloc || 325 allocator == Fortify_Allocator_realloc )) 318 326 { 319 327 sprintf(st_Buffer, 320 "\nFortify: A \"%s\" of 0 bytes attempted at %s.%lu\n",321 st_AllocatorName[allocator], file, line);322 st_Output(st_Buffer);328 "\nFortify: A \"%s\" of 0 bytes attempted at %s.%lu\n", 329 st_AllocatorName[allocator], file, line); 330 st_Output(st_Buffer); 323 331 } 324 332 #endif /* FORTIFY_WARN_ON_ZERO_MALLOC */ … … 326 334 #ifdef FORTIFY_FAIL_ON_ZERO_MALLOC 327 335 if(size == 0 && (allocator == Fortify_Allocator_malloc || 328 allocator == Fortify_Allocator_calloc ||329 allocator == Fortify_Allocator_realloc ))336 allocator == Fortify_Allocator_calloc || 337 allocator == Fortify_Allocator_realloc )) 330 338 { 331 339 #ifdef FORTIFY_WARN_ON_ALLOCATE_FAIL 332 sprintf(st_Buffer, "\nFortify: A \"%s\" of %lu bytes failed at %s.%lu\n",333 st_AllocatorName[allocator], (unsigned long)size, file, line);
![(please configure the [header_logo] section in trac.ini)](/fm2/chrome/site/your_project_logo.png)