bash-4.2-030.patch 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. BASH PATCH REPORT
  2. =================
  3. Bash-Release: 4.2
  4. Patch-ID: bash42-030
  5. Bug-Reported-by: Roman Rakus <rrakus@redhat.com>
  6. Bug-Reference-ID: <4D7DD91E.7040808@redhat.com>
  7. Bug-Reference-URL: http://lists.gnu.org/archive/html/bug-bash/2011-03/msg00126.html
  8. Bug-Description:
  9. When attempting to glob strings in a multibyte locale, and those strings
  10. contain invalid multibyte characters that cause mbsnrtowcs to return 0,
  11. the globbing code loops infinitely.
  12. Patch (apply with `patch -p0'):
  13. *** ../bash-4.2-patched/lib/glob/xmbsrtowcs.c 2010-05-30 18:36:27.000000000 -0400
  14. --- ./lib/glob/xmbsrtowcs.c 2011-03-22 16:06:47.000000000 -0400
  15. ***************
  16. *** 36,39 ****
  17. --- 36,41 ----
  18. #if HANDLE_MULTIBYTE
  19. + #define WSBUF_INC 32
  20. +
  21. #ifndef FREE
  22. # define FREE(x) do { if (x) free (x); } while (0)
  23. ***************
  24. *** 149,153 ****
  25. size_t wcnum; /* Number of wide characters in WSBUF */
  26. mbstate_t state; /* Conversion State */
  27. ! size_t wcslength; /* Number of wide characters produced by the conversion. */
  28. const char *end_or_backslash;
  29. size_t nms; /* Number of multibyte characters to convert at one time. */
  30. --- 151,155 ----
  31. size_t wcnum; /* Number of wide characters in WSBUF */
  32. mbstate_t state; /* Conversion State */
  33. ! size_t n, wcslength; /* Number of wide characters produced by the conversion. */
  34. const char *end_or_backslash;
  35. size_t nms; /* Number of multibyte characters to convert at one time. */
  36. ***************
  37. *** 172,176 ****
  38. tmp_p = p;
  39. tmp_state = state;
  40. ! wcslength = mbsnrtowcs(NULL, &tmp_p, nms, 0, &tmp_state);
  41. /* Conversion failed. */
  42. --- 174,189 ----
  43. tmp_p = p;
  44. tmp_state = state;
  45. !
  46. ! if (nms == 0 && *p == '\\') /* special initial case */
  47. ! nms = wcslength = 1;
  48. ! else
  49. ! wcslength = mbsnrtowcs (NULL, &tmp_p, nms, 0, &tmp_state);
  50. !
  51. ! if (wcslength == 0)
  52. ! {
  53. ! tmp_p = p; /* will need below */
  54. ! tmp_state = state;
  55. ! wcslength = 1; /* take a single byte */
  56. ! }
  57. /* Conversion failed. */
  58. ***************
  59. *** 187,191 ****
  60. wchar_t *wstmp;
  61. ! wsbuf_size = wcnum+wcslength+1; /* 1 for the L'\0' or the potential L'\\' */
  62. wstmp = (wchar_t *) realloc (wsbuf, wsbuf_size * sizeof (wchar_t));
  63. --- 200,205 ----
  64. wchar_t *wstmp;
  65. ! while (wsbuf_size < wcnum+wcslength+1) /* 1 for the L'\0' or the potential L'\\' */
  66. ! wsbuf_size += WSBUF_INC;
  67. wstmp = (wchar_t *) realloc (wsbuf, wsbuf_size * sizeof (wchar_t));
  68. ***************
  69. *** 200,207 ****
  70. /* Perform the conversion. This is assumed to return 'wcslength'.
  71. ! * It may set 'p' to NULL. */
  72. ! mbsnrtowcs(wsbuf+wcnum, &p, nms, wsbuf_size-wcnum, &state);
  73. ! wcnum += wcslength;
  74. if (mbsinit (&state) && (p != NULL) && (*p == '\\'))
  75. --- 214,229 ----
  76. /* Perform the conversion. This is assumed to return 'wcslength'.
  77. ! It may set 'p' to NULL. */
  78. ! n = mbsnrtowcs(wsbuf+wcnum, &p, nms, wsbuf_size-wcnum, &state);
  79. ! /* Compensate for taking single byte on wcs conversion failure above. */
  80. ! if (wcslength == 1 && (n == 0 || n == (size_t)-1))
  81. ! {
  82. ! state = tmp_state;
  83. ! p = tmp_p;
  84. ! wsbuf[wcnum++] = *p++;
  85. ! }
  86. ! else
  87. ! wcnum += wcslength;
  88. if (mbsinit (&state) && (p != NULL) && (*p == '\\'))
  89. ***************
  90. *** 231,236 ****
  91. of DESTP and INDICESP are NULL. */
  92. - #define WSBUF_INC 32
  93. -
  94. size_t
  95. xdupmbstowcs (destp, indicesp, src)
  96. --- 253,256 ----
  97. *** ../bash-4.2-patched/lib/glob/glob.c 2009-11-14 18:39:30.000000000 -0500
  98. --- ./lib/glob/glob.c 2012-07-07 12:09:56.000000000 -0400
  99. ***************
  100. *** 201,206 ****
  101. size_t pat_n, dn_n;
  102. pat_n = xdupmbstowcs (&pat_wc, NULL, pat);
  103. ! dn_n = xdupmbstowcs (&dn_wc, NULL, dname);
  104. ret = 0;
  105. --- 201,209 ----
  106. size_t pat_n, dn_n;
  107. + pat_wc = dn_wc = (wchar_t *)NULL;
  108. +
  109. pat_n = xdupmbstowcs (&pat_wc, NULL, pat);
  110. ! if (pat_n != (size_t)-1)
  111. ! dn_n = xdupmbstowcs (&dn_wc, NULL, dname);
  112. ret = 0;
  113. ***************
  114. *** 222,225 ****
  115. --- 225,230 ----
  116. ret = 1;
  117. }
  118. + else
  119. + ret = skipname (pat, dname, flags);
  120. FREE (pat_wc);
  121. ***************
  122. *** 267,272 ****
  123. n = xdupmbstowcs (&wpathname, NULL, pathname);
  124. if (n == (size_t) -1)
  125. ! /* Something wrong. */
  126. ! return;
  127. orig_wpathname = wpathname;
  128. --- 272,280 ----
  129. n = xdupmbstowcs (&wpathname, NULL, pathname);
  130. if (n == (size_t) -1)
  131. ! {
  132. ! /* Something wrong. Fall back to single-byte */
  133. ! udequote_pathname (pathname);
  134. ! return;
  135. ! }
  136. orig_wpathname = wpathname;
  137. *** ../bash-4.2-patched/patchlevel.h Sat Jun 12 20:14:48 2010
  138. --- ./patchlevel.h Thu Feb 24 21:41:34 2011
  139. ***************
  140. *** 26,30 ****
  141. looks for to find the patch level (for the sccs version string). */
  142. ! #define PATCHLEVEL 29
  143. #endif /* _PATCHLEVEL_H_ */
  144. --- 26,30 ----
  145. looks for to find the patch level (for the sccs version string). */
  146. ! #define PATCHLEVEL 30
  147. #endif /* _PATCHLEVEL_H_ */