diff options
Diffstat (limited to 'src/lib/libcrypto/rand/rand_win.c')
| -rw-r--r-- | src/lib/libcrypto/rand/rand_win.c | 71 |
1 files changed, 11 insertions, 60 deletions
diff --git a/src/lib/libcrypto/rand/rand_win.c b/src/lib/libcrypto/rand/rand_win.c index 5d134e186b..00dbe4232c 100644 --- a/src/lib/libcrypto/rand/rand_win.c +++ b/src/lib/libcrypto/rand/rand_win.c | |||
| @@ -463,7 +463,7 @@ int RAND_poll(void) | |||
| 463 | PROCESSENTRY32 p; | 463 | PROCESSENTRY32 p; |
| 464 | THREADENTRY32 t; | 464 | THREADENTRY32 t; |
| 465 | MODULEENTRY32 m; | 465 | MODULEENTRY32 m; |
| 466 | DWORD starttime = 0; | 466 | DWORD stoptime = 0; |
| 467 | 467 | ||
| 468 | snap = (CREATETOOLHELP32SNAPSHOT) | 468 | snap = (CREATETOOLHELP32SNAPSHOT) |
| 469 | GetProcAddress(kernel, "CreateToolhelp32Snapshot"); | 469 | GetProcAddress(kernel, "CreateToolhelp32Snapshot"); |
| @@ -494,29 +494,12 @@ int RAND_poll(void) | |||
| 494 | * each entry. Consider each field a source of 1 byte | 494 | * each entry. Consider each field a source of 1 byte |
| 495 | * of entropy. | 495 | * of entropy. |
| 496 | */ | 496 | */ |
| 497 | ZeroMemory(&hlist, sizeof(HEAPLIST32)); | ||
| 498 | hlist.dwSize = sizeof(HEAPLIST32); | 497 | hlist.dwSize = sizeof(HEAPLIST32); |
| 499 | if (good) starttime = GetTickCount(); | 498 | if (good) stoptime = GetTickCount() + MAXDELAY; |
| 500 | #ifdef _MSC_VER | ||
| 501 | if (heaplist_first(handle, &hlist)) | 499 | if (heaplist_first(handle, &hlist)) |
| 502 | { | ||
| 503 | /* | ||
| 504 | following discussion on dev ML, exception on WinCE (or other Win | ||
| 505 | platform) is theoretically of unknown origin; prevent infinite | ||
| 506 | loop here when this theoretical case occurs; otherwise cope with | ||
| 507 | the expected (MSDN documented) exception-throwing behaviour of | ||
| 508 | Heap32Next() on WinCE. | ||
| 509 | |||
| 510 | based on patch in original message by Tanguy Fautré (2009/03/02) | ||
| 511 | Subject: RAND_poll() and CreateToolhelp32Snapshot() stability | ||
| 512 | */ | ||
| 513 | int ex_cnt_limit = 42; | ||
| 514 | do | 500 | do |
| 515 | { | 501 | { |
| 516 | RAND_add(&hlist, hlist.dwSize, 3); | 502 | RAND_add(&hlist, hlist.dwSize, 3); |
| 517 | __try | ||
| 518 | { | ||
| 519 | ZeroMemory(&hentry, sizeof(HEAPENTRY32)); | ||
| 520 | hentry.dwSize = sizeof(HEAPENTRY32); | 503 | hentry.dwSize = sizeof(HEAPENTRY32); |
| 521 | if (heap_first(&hentry, | 504 | if (heap_first(&hentry, |
| 522 | hlist.th32ProcessID, | 505 | hlist.th32ProcessID, |
| @@ -527,42 +510,10 @@ int RAND_poll(void) | |||
| 527 | RAND_add(&hentry, | 510 | RAND_add(&hentry, |
| 528 | hentry.dwSize, 5); | 511 | hentry.dwSize, 5); |
| 529 | while (heap_next(&hentry) | 512 | while (heap_next(&hentry) |
| 530 | && (!good || (GetTickCount()-starttime)<MAXDELAY) | ||
| 531 | && --entrycnt > 0); | 513 | && --entrycnt > 0); |
| 532 | } | 514 | } |
| 533 | } | 515 | } while (heaplist_next(handle, |
| 534 | __except (EXCEPTION_EXECUTE_HANDLER) | 516 | &hlist) && GetTickCount() < stoptime); |
| 535 | { | ||
| 536 | /* ignore access violations when walking the heap list */ | ||
| 537 | ex_cnt_limit--; | ||
| 538 | } | ||
| 539 | } while (heaplist_next(handle, &hlist) | ||
| 540 | && (!good || (GetTickCount()-starttime)<MAXDELAY) | ||
| 541 | && ex_cnt_limit > 0); | ||
| 542 | } | ||
| 543 | |||
| 544 | #else | ||
| 545 | if (heaplist_first(handle, &hlist)) | ||
| 546 | { | ||
| 547 | do | ||
| 548 | { | ||
| 549 | RAND_add(&hlist, hlist.dwSize, 3); | ||
| 550 | hentry.dwSize = sizeof(HEAPENTRY32); | ||
| 551 | if (heap_first(&hentry, | ||
| 552 | hlist.th32ProcessID, | ||
| 553 | hlist.th32HeapID)) | ||
| 554 | { | ||
| 555 | int entrycnt = 80; | ||
| 556 | do | ||
| 557 | RAND_add(&hentry, | ||
| 558 | hentry.dwSize, 5); | ||
| 559 | while (heap_next(&hentry) | ||
| 560 | && --entrycnt > 0); | ||
| 561 | } | ||
| 562 | } while (heaplist_next(handle, &hlist) | ||
| 563 | && (!good || (GetTickCount()-starttime)<MAXDELAY)); | ||
| 564 | } | ||
| 565 | #endif | ||
| 566 | 517 | ||
| 567 | /* process walking */ | 518 | /* process walking */ |
| 568 | /* PROCESSENTRY32 contains 9 fields that will change | 519 | /* PROCESSENTRY32 contains 9 fields that will change |
| @@ -571,11 +522,11 @@ int RAND_poll(void) | |||
| 571 | */ | 522 | */ |
| 572 | p.dwSize = sizeof(PROCESSENTRY32); | 523 | p.dwSize = sizeof(PROCESSENTRY32); |
| 573 | 524 | ||
| 574 | if (good) starttime = GetTickCount(); | 525 | if (good) stoptime = GetTickCount() + MAXDELAY; |
| 575 | if (process_first(handle, &p)) | 526 | if (process_first(handle, &p)) |
| 576 | do | 527 | do |
| 577 | RAND_add(&p, p.dwSize, 9); | 528 | RAND_add(&p, p.dwSize, 9); |
| 578 | while (process_next(handle, &p) && (!good || (GetTickCount()-starttime)<MAXDELAY)); | 529 | while (process_next(handle, &p) && GetTickCount() < stoptime); |
| 579 | 530 | ||
| 580 | /* thread walking */ | 531 | /* thread walking */ |
| 581 | /* THREADENTRY32 contains 6 fields that will change | 532 | /* THREADENTRY32 contains 6 fields that will change |
| @@ -583,11 +534,11 @@ int RAND_poll(void) | |||
| 583 | * 1 byte of entropy. | 534 | * 1 byte of entropy. |
| 584 | */ | 535 | */ |
| 585 | t.dwSize = sizeof(THREADENTRY32); | 536 | t.dwSize = sizeof(THREADENTRY32); |
| 586 | if (good) starttime = GetTickCount(); | 537 | if (good) stoptime = GetTickCount() + MAXDELAY; |
| 587 | if (thread_first(handle, &t)) | 538 | if (thread_first(handle, &t)) |
| 588 | do | 539 | do |
| 589 | RAND_add(&t, t.dwSize, 6); | 540 | RAND_add(&t, t.dwSize, 6); |
| 590 | while (thread_next(handle, &t) && (!good || (GetTickCount()-starttime)<MAXDELAY)); | 541 | while (thread_next(handle, &t) && GetTickCount() < stoptime); |
| 591 | 542 | ||
| 592 | /* module walking */ | 543 | /* module walking */ |
| 593 | /* MODULEENTRY32 contains 9 fields that will change | 544 | /* MODULEENTRY32 contains 9 fields that will change |
| @@ -595,12 +546,12 @@ int RAND_poll(void) | |||
| 595 | * 1 byte of entropy. | 546 | * 1 byte of entropy. |
| 596 | */ | 547 | */ |
| 597 | m.dwSize = sizeof(MODULEENTRY32); | 548 | m.dwSize = sizeof(MODULEENTRY32); |
| 598 | if (good) starttime = GetTickCount(); | 549 | if (good) stoptime = GetTickCount() + MAXDELAY; |
| 599 | if (module_first(handle, &m)) | 550 | if (module_first(handle, &m)) |
| 600 | do | 551 | do |
| 601 | RAND_add(&m, m.dwSize, 9); | 552 | RAND_add(&m, m.dwSize, 9); |
| 602 | while (module_next(handle, &m) | 553 | while (module_next(handle, &m) |
| 603 | && (!good || (GetTickCount()-starttime)<MAXDELAY)); | 554 | && (GetTickCount() < stoptime)); |
| 604 | if (close_snap) | 555 | if (close_snap) |
| 605 | close_snap(handle); | 556 | close_snap(handle); |
| 606 | else | 557 | else |
| @@ -750,7 +701,7 @@ static void readscreen(void) | |||
| 750 | int y; /* y-coordinate of screen lines to grab */ | 701 | int y; /* y-coordinate of screen lines to grab */ |
| 751 | int n = 16; /* number of screen lines to grab at a time */ | 702 | int n = 16; /* number of screen lines to grab at a time */ |
| 752 | 703 | ||
| 753 | if (GetVersion() < 0x80000000 && OPENSSL_isservice()>0) | 704 | if (GetVersion() >= 0x80000000 || !OPENSSL_isservice()) |
| 754 | return; | 705 | return; |
| 755 | 706 | ||
| 756 | /* Create a screen DC and a memory DC compatible to screen DC */ | 707 | /* Create a screen DC and a memory DC compatible to screen DC */ |
