Advertisement
Guest User

rand_win.c diff between OpenSSL 0.9.8k and 1.0.0

a guest
May 24th, 2010
481
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 4.78 KB | None | 0 0
  1. --- openssl/crypto/rand/rand_win-0.9.8k.c   Fri Oct 14 05:07:28 2005
  2. +++ openssl/crypto/rand/rand_win-1.0.0.c    Tue Mar 23 09:44:35 2010
  3. @@ -463,7 +463,7 @@
  4.         PROCESSENTRY32 p;
  5.         THREADENTRY32 t;
  6.         MODULEENTRY32 m;
  7. -       DWORD stoptime = 0;
  8. +       DWORD starttime = 0;
  9.  
  10.         snap = (CREATETOOLHELP32SNAPSHOT)
  11.             GetProcAddress(kernel, "CreateToolhelp32Snapshot");
  12. @@ -494,12 +494,29 @@
  13.                           * each entry.  Consider each field a source of 1 byte
  14.                           * of entropy.
  15.                           */
  16. +           ZeroMemory(&hlist, sizeof(HEAPLIST32));
  17.             hlist.dwSize = sizeof(HEAPLIST32);     
  18. -           if (good) stoptime = GetTickCount() + MAXDELAY;
  19. +           if (good) starttime = GetTickCount();
  20. +#ifdef _MSC_VER
  21.             if (heaplist_first(handle, &hlist))
  22. +               {
  23. +               /*
  24. +                  following discussion on dev ML, exception on WinCE (or other Win
  25. +                  platform) is theoretically of unknown origin; prevent infinite
  26. +                  loop here when this theoretical case occurs; otherwise cope with
  27. +                  the expected (MSDN documented) exception-throwing behaviour of
  28. +                  Heap32Next() on WinCE.
  29. +
  30. +                  based on patch in original message by Tanguy Fautré (2009/03/02)
  31. +                      Subject: RAND_poll() and CreateToolhelp32Snapshot() stability
  32. +                */
  33. +               int ex_cnt_limit = 42;
  34.                 do
  35.                     {
  36.                     RAND_add(&hlist, hlist.dwSize, 3);
  37. +                   __try
  38. +                       {
  39. +                       ZeroMemory(&hentry, sizeof(HEAPENTRY32));
  40.                     hentry.dwSize = sizeof(HEAPENTRY32);
  41.                     if (heap_first(&hentry,
  42.                         hlist.th32ProcessID,
  43. @@ -510,11 +527,43 @@
  44.                             RAND_add(&hentry,
  45.                                 hentry.dwSize, 5);
  46.                         while (heap_next(&hentry)
  47. +                       && (!good || (GetTickCount()-starttime)<MAXDELAY)
  48.                             && --entrycnt > 0);
  49.                         }
  50. -                   } while (heaplist_next(handle,
  51. -                       &hlist) && GetTickCount() < stoptime);
  52. +                       }
  53. +                   __except (EXCEPTION_EXECUTE_HANDLER)
  54. +                       {
  55. +                           /* ignore access violations when walking the heap list */
  56. +                           ex_cnt_limit--;
  57. +                       }
  58. +                   } while (heaplist_next(handle, &hlist)
  59. +                       && (!good || (GetTickCount()-starttime)<MAXDELAY)
  60. +                       && ex_cnt_limit > 0);
  61. +               }
  62.  
  63. +#else
  64. +           if (heaplist_first(handle, &hlist))
  65. +               {
  66. +               do
  67. +                   {
  68. +                   RAND_add(&hlist, hlist.dwSize, 3);
  69. +                   hentry.dwSize = sizeof(HEAPENTRY32);
  70. +                   if (heap_first(&hentry,
  71. +                       hlist.th32ProcessID,
  72. +                       hlist.th32HeapID))
  73. +                       {
  74. +                       int entrycnt = 80;
  75. +                       do
  76. +                           RAND_add(&hentry,
  77. +                               hentry.dwSize, 5);
  78. +                       while (heap_next(&hentry)
  79. +                           && --entrycnt > 0);
  80. +                       }
  81. +                   } while (heaplist_next(handle, &hlist)
  82. +                       && (!good || (GetTickCount()-starttime)<MAXDELAY));
  83. +               }
  84. +#endif
  85. +
  86.             /* process walking */
  87.                          /* PROCESSENTRY32 contains 9 fields that will change
  88.                           * with each entry.  Consider each field a source of
  89. @@ -522,11 +571,11 @@
  90.                           */
  91.             p.dwSize = sizeof(PROCESSENTRY32);
  92.        
  93. -           if (good) stoptime = GetTickCount() + MAXDELAY;
  94. +           if (good) starttime = GetTickCount();
  95.             if (process_first(handle, &p))
  96.                 do
  97.                     RAND_add(&p, p.dwSize, 9);
  98. -               while (process_next(handle, &p) && GetTickCount() < stoptime);
  99. +               while (process_next(handle, &p) && (!good || (GetTickCount()-starttime)<MAXDELAY));
  100.  
  101.             /* thread walking */
  102.                          /* THREADENTRY32 contains 6 fields that will change
  103. @@ -534,11 +583,11 @@
  104.                           * 1 byte of entropy.
  105.                           */
  106.             t.dwSize = sizeof(THREADENTRY32);
  107. -           if (good) stoptime = GetTickCount() + MAXDELAY;
  108. +           if (good) starttime = GetTickCount();
  109.             if (thread_first(handle, &t))
  110.                 do
  111.                     RAND_add(&t, t.dwSize, 6);
  112. -               while (thread_next(handle, &t) && GetTickCount() < stoptime);
  113. +               while (thread_next(handle, &t) && (!good || (GetTickCount()-starttime)<MAXDELAY));
  114.  
  115.             /* module walking */
  116.                          /* MODULEENTRY32 contains 9 fields that will change
  117. @@ -546,12 +595,12 @@
  118.                           * 1 byte of entropy.
  119.                           */
  120.             m.dwSize = sizeof(MODULEENTRY32);
  121. -           if (good) stoptime = GetTickCount() + MAXDELAY;
  122. +           if (good) starttime = GetTickCount();
  123.             if (module_first(handle, &m))
  124.                 do
  125.                     RAND_add(&m, m.dwSize, 9);
  126.                 while (module_next(handle, &m)
  127. -                           && (GetTickCount() < stoptime));
  128. +                           && (!good || (GetTickCount()-starttime)<MAXDELAY));
  129.             if (close_snap)
  130.                 close_snap(handle);
  131.             else
  132. @@ -701,7 +750,7 @@
  133.    int      y;      /* y-coordinate of screen lines to grab */
  134.    int      n = 16;     /* number of screen lines to grab at a time */
  135.  
  136. -  if (GetVersion() >= 0x80000000 || !OPENSSL_isservice())
  137. +  if (GetVersion() < 0x80000000 && OPENSSL_isservice()>0)
  138.      return;
  139.  
  140.    /* Create a screen DC and a memory DC compatible to screen DC */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement