]>
Commit | Line | Data |
---|---|---|
4e9fe84f JB |
1 | BASH PATCH REPORT |
2 | ================= | |
3 | ||
4 | Bash-Release: 3.0 | |
5 | Patch-ID: bash30-004 | |
6 | ||
7 | Bug-Reported-by: Stephane Chazelas <stephane_chazelas@yahoo.fr> | |
8 | Bug-Reference-ID: <20040902131957.GC1860@frhdtmp102861.morse.corp.wan> | |
9 | Bug-Reference-URL: http://lists.gnu.org/archive/html/bug-bash/2004-07/msg00291.html | |
10 | ||
11 | Bug-Description: | |
12 | ||
13 | Calculation of lengths and offsets for parameter string length and substring | |
14 | expansion does not correctly account for multibyte characters. | |
15 | ||
16 | Patch: | |
17 | ||
18 | *** ../bash-3.0/subst.c Sun Jul 4 13:56:13 2004 | |
19 | --- subst.c Thu Aug 12 13:36:17 2004 | |
20 | *************** | |
21 | *** 4692,4695 **** | |
22 | --- 4692,4715 ---- | |
23 | } | |
24 | ||
25 | + #if defined (HANDLE_MULTIBYTE) | |
26 | + size_t | |
27 | + mbstrlen (s) | |
28 | + const char *s; | |
29 | + { | |
30 | + size_t clen, nc; | |
31 | + mbstate_t mbs; | |
32 | + | |
33 | + nc = 0; | |
34 | + memset (&mbs, 0, sizeof (mbs)); | |
35 | + while ((clen = mbrlen(s, MB_CUR_MAX, &mbs)) != 0 && (MB_INVALIDCH(clen) == 0)) | |
36 | + { | |
37 | + s += clen; | |
38 | + nc++; | |
39 | + } | |
40 | + return nc; | |
41 | + } | |
42 | + #endif | |
43 | + | |
44 | + | |
45 | /* Handle the parameter brace expansion that requires us to return the | |
46 | length of a parameter. */ | |
47 | *************** | |
48 | *** 4747,4758 **** | |
49 | { | |
50 | t = get_dollar_var_value (arg_index); | |
51 | ! number = STRLEN (t); | |
52 | FREE (t); | |
53 | } | |
54 | #if defined (ARRAY_VARS) | |
55 | ! else if ((var = find_variable (name + 1)) && array_p (var)) | |
56 | { | |
57 | t = array_reference (array_cell (var), 0); | |
58 | ! number = STRLEN (t); | |
59 | } | |
60 | #endif | |
61 | --- 4767,4778 ---- | |
62 | { | |
63 | t = get_dollar_var_value (arg_index); | |
64 | ! number = MB_STRLEN (t); | |
65 | FREE (t); | |
66 | } | |
67 | #if defined (ARRAY_VARS) | |
68 | ! else if ((var = find_variable (name + 1)) && (invisible_p (var) == 0) && array_p (var)) | |
69 | { | |
70 | t = array_reference (array_cell (var), 0); | |
71 | ! number = MB_STRLEN (t); | |
72 | } | |
73 | #endif | |
74 | *************** | |
75 | *** 4767,4771 **** | |
76 | dispose_words (list); | |
77 | ||
78 | ! number = STRLEN (t); | |
79 | FREE (t); | |
80 | } | |
81 | --- 4787,4791 ---- | |
82 | dispose_words (list); | |
83 | ||
84 | ! number = MB_STRLEN (t); | |
85 | FREE (t); | |
86 | } | |
87 | *************** | |
88 | *** 4872,4876 **** | |
89 | case VT_VARIABLE: | |
90 | case VT_ARRAYMEMBER: | |
91 | ! len = strlen (value); | |
92 | break; | |
93 | case VT_POSPARMS: | |
94 | --- 4892,4896 ---- | |
95 | case VT_VARIABLE: | |
96 | case VT_ARRAYMEMBER: | |
97 | ! len = MB_STRLEN (value); | |
98 | break; | |
99 | case VT_POSPARMS: | |
100 | *** ../bash-3.0/include/shmbutil.h Mon Apr 19 09:59:42 2004 | |
101 | --- include/shmbutil.h Thu Sep 2 15:20:47 2004 | |
102 | *************** | |
103 | *** 32,35 **** | |
104 | --- 32,37 ---- | |
105 | extern size_t xdupmbstowcs __P((wchar_t **, char ***, const char *)); | |
106 | ||
107 | + extern size_t mbstrlen __P((const char *)); | |
108 | + | |
109 | extern char *xstrchr __P((const char *, int)); | |
110 | ||
111 | *************** | |
112 | *** 39,42 **** | |
113 | --- 41,47 ---- | |
114 | #endif | |
115 | ||
116 | + #define MBSLEN(s) (((s) && (s)[0]) ? ((s)[1] ? mbstrlen (s) : 1) : 0) | |
117 | + #define MB_STRLEN(s) ((MB_CUR_MAX > 1) ? MBSLEN (s) : STRLEN (s)) | |
118 | + | |
119 | #else /* !HANDLE_MULTIBYTE */ | |
120 | ||
121 | *************** | |
122 | *** 54,57 **** | |
123 | --- 59,64 ---- | |
124 | #define MB_NULLWCH(x) (0) | |
125 | #endif | |
126 | + | |
127 | + #define MB_STRLEN(s) (STRLEN(s)) | |
128 | ||
129 | #endif /* !HANDLE_MULTIBYTE */ | |
130 | ||
131 | *** ../bash-3.0/patchlevel.h Wed Aug 22 08:05:39 2001 | |
132 | --- patchlevel.h Thu Sep 2 15:04:32 2004 | |
133 | *************** | |
134 | *** 26,30 **** | |
135 | looks for to find the patch level (for the sccs version string). */ | |
136 | ||
137 | ! #define PATCHLEVEL 3 | |
138 | ||
139 | #endif /* _PATCHLEVEL_H_ */ | |
140 | --- 26,30 ---- | |
141 | looks for to find the patch level (for the sccs version string). */ | |
142 | ||
143 | ! #define PATCHLEVEL 4 | |
144 | ||
145 | #endif /* _PATCHLEVEL_H_ */ |