bash44-020 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. BASH PATCH REPORT
  2. =================
  3. Bash-Release: 4.4
  4. Patch-ID: bash44-020
  5. Bug-Reported-by: Graham Northup <northug@clarkson.edu>
  6. Bug-Reference-ID: <537530c3-61f0-349b-9de6-fa4e2487f428@clarkson.edu>
  7. Bug-Reference-URL: http://lists.gnu.org/archive/html/bug-bash/2017-02/msg00025.html
  8. Bug-Description:
  9. In circumstances involving long-running scripts that create and reap many
  10. processes, it is possible for the hash table bash uses to store exit
  11. statuses from asynchronous processes to develop loops. This patch fixes
  12. the loop causes and adds code to detect any future loops.
  13. Patch (apply with `patch -p0'):
  14. *** ../bash-4.4-patched/jobs.c 2016-11-11 13:42:55.000000000 -0500
  15. --- jobs.c 2017-02-22 15:16:28.000000000 -0500
  16. ***************
  17. *** 813,818 ****
  18. struct pidstat *ps;
  19. ! bucket = pshash_getbucket (pid);
  20. ! psi = bgp_getindex ();
  21. ps = &bgpids.storage[psi];
  22. --- 796,815 ----
  23. struct pidstat *ps;
  24. ! /* bucket == existing chain of pids hashing to same value
  25. ! psi = where were going to put this pid/status */
  26. !
  27. ! bucket = pshash_getbucket (pid); /* index into pidstat_table */
  28. ! psi = bgp_getindex (); /* bgpids.head, index into storage */
  29. !
  30. ! /* XXX - what if psi == *bucket? */
  31. ! if (psi == *bucket)
  32. ! {
  33. ! #ifdef DEBUG
  34. ! internal_warning ("hashed pid %d (pid %d) collides with bgpids.head, skipping", psi, pid);
  35. ! #endif
  36. ! bgpids.storage[psi].pid = NO_PID; /* make sure */
  37. ! psi = bgp_getindex (); /* skip to next one */
  38. ! }
  39. !
  40. ps = &bgpids.storage[psi];
  41. ***************
  42. *** 842,845 ****
  43. --- 839,843 ----
  44. {
  45. struct pidstat *ps;
  46. + ps_index_t *bucket;
  47. ps = &bgpids.storage[psi];
  48. ***************
  49. *** 847,856 ****
  50. return;
  51. ! if (ps->bucket_next != NO_PID)
  52. bgpids.storage[ps->bucket_next].bucket_prev = ps->bucket_prev;
  53. ! if (ps->bucket_prev != NO_PID)
  54. bgpids.storage[ps->bucket_prev].bucket_next = ps->bucket_next;
  55. else
  56. ! *(pshash_getbucket (ps->pid)) = ps->bucket_next;
  57. }
  58. --- 845,861 ----
  59. return;
  60. ! if (ps->bucket_next != NO_PIDSTAT)
  61. bgpids.storage[ps->bucket_next].bucket_prev = ps->bucket_prev;
  62. ! if (ps->bucket_prev != NO_PIDSTAT)
  63. bgpids.storage[ps->bucket_prev].bucket_next = ps->bucket_next;
  64. else
  65. ! {
  66. ! bucket = pshash_getbucket (ps->pid);
  67. ! *bucket = ps->bucket_next; /* deleting chain head in hash table */
  68. ! }
  69. !
  70. ! /* clear out this cell, just in case */
  71. ! ps->pid = NO_PID;
  72. ! ps->bucket_next = ps->bucket_prev = NO_PIDSTAT;
  73. }
  74. ***************
  75. *** 859,863 ****
  76. pid_t pid;
  77. {
  78. ! ps_index_t psi;
  79. if (bgpids.storage == 0 || bgpids.nalloc == 0 || bgpids.npid == 0)
  80. --- 864,868 ----
  81. pid_t pid;
  82. {
  83. ! ps_index_t psi, orig_psi;
  84. if (bgpids.storage == 0 || bgpids.nalloc == 0 || bgpids.npid == 0)
  85. ***************
  86. *** 865,871 ****
  87. /* Search chain using hash to find bucket in pidstat_table */
  88. ! for (psi = *(pshash_getbucket (pid)); psi != NO_PIDSTAT; psi = bgpids.storage[psi].bucket_next)
  89. ! if (bgpids.storage[psi].pid == pid)
  90. ! break;
  91. if (psi == NO_PIDSTAT)
  92. --- 870,883 ----
  93. /* Search chain using hash to find bucket in pidstat_table */
  94. ! for (orig_psi = psi = *(pshash_getbucket (pid)); psi != NO_PIDSTAT; psi = bgpids.storage[psi].bucket_next)
  95. ! {
  96. ! if (bgpids.storage[psi].pid == pid)
  97. ! break;
  98. ! if (orig_psi == bgpids.storage[psi].bucket_next) /* catch reported bug */
  99. ! {
  100. ! internal_warning ("bgp_delete: LOOP: psi (%d) == storage[psi].bucket_next", psi);
  101. ! return 0;
  102. ! }
  103. ! }
  104. if (psi == NO_PIDSTAT)
  105. ***************
  106. *** 905,909 ****
  107. pid_t pid;
  108. {
  109. ! ps_index_t psi;
  110. if (bgpids.storage == 0 || bgpids.nalloc == 0 || bgpids.npid == 0)
  111. --- 917,921 ----
  112. pid_t pid;
  113. {
  114. ! ps_index_t psi, orig_psi;
  115. if (bgpids.storage == 0 || bgpids.nalloc == 0 || bgpids.npid == 0)
  116. ***************
  117. *** 911,917 ****
  118. /* Search chain using hash to find bucket in pidstat_table */
  119. ! for (psi = *(pshash_getbucket (pid)); psi != NO_PIDSTAT; psi = bgpids.storage[psi].bucket_next)
  120. ! if (bgpids.storage[psi].pid == pid)
  121. ! return (bgpids.storage[psi].status);
  122. return -1;
  123. --- 923,936 ----
  124. /* Search chain using hash to find bucket in pidstat_table */
  125. ! for (orig_psi = psi = *(pshash_getbucket (pid)); psi != NO_PIDSTAT; psi = bgpids.storage[psi].bucket_next)
  126. ! {
  127. ! if (bgpids.storage[psi].pid == pid)
  128. ! return (bgpids.storage[psi].status);
  129. ! if (orig_psi == bgpids.storage[psi].bucket_next) /* catch reported bug */
  130. ! {
  131. ! internal_warning ("bgp_search: LOOP: psi (%d) == storage[psi].bucket_next", psi);
  132. ! return -1;
  133. ! }
  134. ! }
  135. return -1;
  136. *** ../bash-4.4/patchlevel.h 2016-06-22 14:51:03.000000000 -0400
  137. --- patchlevel.h 2016-10-01 11:01:28.000000000 -0400
  138. ***************
  139. *** 26,30 ****
  140. looks for to find the patch level (for the sccs version string). */
  141. ! #define PATCHLEVEL 19
  142. #endif /* _PATCHLEVEL_H_ */
  143. --- 26,30 ----
  144. looks for to find the patch level (for the sccs version string). */
  145. ! #define PATCHLEVEL 20
  146. #endif /* _PATCHLEVEL_H_ */