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, 60 insertions, 11 deletions
diff --git a/src/lib/libcrypto/rand/rand_win.c b/src/lib/libcrypto/rand/rand_win.c index 00dbe4232c..5d134e186b 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 stoptime = 0; | 466 | DWORD starttime = 0; |
| 467 | 467 | ||
| 468 | snap = (CREATETOOLHELP32SNAPSHOT) | 468 | snap = (CREATETOOLHELP32SNAPSHOT) |
| 469 | GetProcAddress(kernel, "CreateToolhelp32Snapshot"); | 469 | GetProcAddress(kernel, "CreateToolhelp32Snapshot"); |
| @@ -494,12 +494,29 @@ 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)); | ||
| 497 | hlist.dwSize = sizeof(HEAPLIST32); | 498 | hlist.dwSize = sizeof(HEAPLIST32); |
| 498 | if (good) stoptime = GetTickCount() + MAXDELAY; | 499 | if (good) starttime = GetTickCount(); |
| 500 | #ifdef _MSC_VER | ||
| 499 | if (heaplist_first(handle, &hlist)) | 501 | 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; | ||
| 500 | do | 514 | do |
| 501 | { | 515 | { |
| 502 | RAND_add(&hlist, hlist.dwSize, 3); | 516 | RAND_add(&hlist, hlist.dwSize, 3); |
| 517 | __try | ||
| 518 | { | ||
| 519 | ZeroMemory(&hentry, sizeof(HEAPENTRY32)); | ||
| 503 | hentry.dwSize = sizeof(HEAPENTRY32); | 520 | hentry.dwSize = sizeof(HEAPENTRY32); |
| 504 | if (heap_first(&hentry, | 521 | if (heap_first(&hentry, |
| 505 | hlist.th32ProcessID, | 522 | hlist.th32ProcessID, |
| @@ -510,10 +527,42 @@ int RAND_poll(void) | |||
| 510 | RAND_add(&hentry, | 527 | RAND_add(&hentry, |
| 511 | hentry.dwSize, 5); | 528 | hentry.dwSize, 5); |
| 512 | while (heap_next(&hentry) | 529 | while (heap_next(&hentry) |
| 530 | && (!good || (GetTickCount()-starttime)<MAXDELAY) | ||
| 513 | && --entrycnt > 0); | 531 | && --entrycnt > 0); |
| 514 | } | 532 | } |
| 515 | } while (heaplist_next(handle, | 533 | } |
| 516 | &hlist) && GetTickCount() < stoptime); | 534 | __except (EXCEPTION_EXECUTE_HANDLER) |
| 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 | ||
| 517 | 566 | ||
| 518 | /* process walking */ | 567 | /* process walking */ |
| 519 | /* PROCESSENTRY32 contains 9 fields that will change | 568 | /* PROCESSENTRY32 contains 9 fields that will change |
| @@ -522,11 +571,11 @@ int RAND_poll(void) | |||
| 522 | */ | 571 | */ |
| 523 | p.dwSize = sizeof(PROCESSENTRY32); | 572 | p.dwSize = sizeof(PROCESSENTRY32); |
| 524 | 573 | ||
| 525 | if (good) stoptime = GetTickCount() + MAXDELAY; | 574 | if (good) starttime = GetTickCount(); |
| 526 | if (process_first(handle, &p)) | 575 | if (process_first(handle, &p)) |
| 527 | do | 576 | do |
| 528 | RAND_add(&p, p.dwSize, 9); | 577 | RAND_add(&p, p.dwSize, 9); |
| 529 | while (process_next(handle, &p) && GetTickCount() < stoptime); | 578 | while (process_next(handle, &p) && (!good || (GetTickCount()-starttime)<MAXDELAY)); |
| 530 | 579 | ||
| 531 | /* thread walking */ | 580 | /* thread walking */ |
| 532 | /* THREADENTRY32 contains 6 fields that will change | 581 | /* THREADENTRY32 contains 6 fields that will change |
| @@ -534,11 +583,11 @@ int RAND_poll(void) | |||
| 534 | * 1 byte of entropy. | 583 | * 1 byte of entropy. |
| 535 | */ | 584 | */ |
| 536 | t.dwSize = sizeof(THREADENTRY32); | 585 | t.dwSize = sizeof(THREADENTRY32); |
| 537 | if (good) stoptime = GetTickCount() + MAXDELAY; | 586 | if (good) starttime = GetTickCount(); |
| 538 | if (thread_first(handle, &t)) | 587 | if (thread_first(handle, &t)) |
| 539 | do | 588 | do |
| 540 | RAND_add(&t, t.dwSize, 6); | 589 | RAND_add(&t, t.dwSize, 6); |
| 541 | while (thread_next(handle, &t) && GetTickCount() < stoptime); | 590 | while (thread_next(handle, &t) && (!good || (GetTickCount()-starttime)<MAXDELAY)); |
| 542 | 591 | ||
| 543 | /* module walking */ | 592 | /* module walking */ |
| 544 | /* MODULEENTRY32 contains 9 fields that will change | 593 | /* MODULEENTRY32 contains 9 fields that will change |
| @@ -546,12 +595,12 @@ int RAND_poll(void) | |||
| 546 | * 1 byte of entropy. | 595 | * 1 byte of entropy. |
| 547 | */ | 596 | */ |
| 548 | m.dwSize = sizeof(MODULEENTRY32); | 597 | m.dwSize = sizeof(MODULEENTRY32); |
| 549 | if (good) stoptime = GetTickCount() + MAXDELAY; | 598 | if (good) starttime = GetTickCount(); |
| 550 | if (module_first(handle, &m)) | 599 | if (module_first(handle, &m)) |
| 551 | do | 600 | do |
| 552 | RAND_add(&m, m.dwSize, 9); | 601 | RAND_add(&m, m.dwSize, 9); |
| 553 | while (module_next(handle, &m) | 602 | while (module_next(handle, &m) |
| 554 | && (GetTickCount() < stoptime)); | 603 | && (!good || (GetTickCount()-starttime)<MAXDELAY)); |
| 555 | if (close_snap) | 604 | if (close_snap) |
| 556 | close_snap(handle); | 605 | close_snap(handle); |
| 557 | else | 606 | else |
| @@ -701,7 +750,7 @@ static void readscreen(void) | |||
| 701 | int y; /* y-coordinate of screen lines to grab */ | 750 | int y; /* y-coordinate of screen lines to grab */ |
| 702 | int n = 16; /* number of screen lines to grab at a time */ | 751 | int n = 16; /* number of screen lines to grab at a time */ |
| 703 | 752 | ||
| 704 | if (GetVersion() >= 0x80000000 || !OPENSSL_isservice()) | 753 | if (GetVersion() < 0x80000000 && OPENSSL_isservice()>0) |
| 705 | return; | 754 | return; |
| 706 | 755 | ||
| 707 | /* Create a screen DC and a memory DC compatible to screen DC */ | 756 | /* Create a screen DC and a memory DC compatible to screen DC */ |
