summaryrefslogtreecommitdiffstats
path: root/package/bash/bash30-004
blob: b18e54c588faf53929f0a722fe0638c7d7b67be6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
			     BASH PATCH REPORT
			     =================

Bash-Release: 3.0
Patch-ID: bash30-004

Bug-Reported-by: Stephane Chazelas <stephane_chazelas@yahoo.fr>
Bug-Reference-ID: <20040902131957.GC1860@frhdtmp102861.morse.corp.wan>
Bug-Reference-URL: http://lists.gnu.org/archive/html/bug-bash/2004-07/msg00291.html

Bug-Description:

Calculation of lengths and offsets for parameter string length and substring
expansion does not correctly account for multibyte characters.

Patch:

 *** ../bash-3.0/subst.c	Sun Jul  4 13:56:13 2004
--- subst.c	Thu Aug 12 13:36:17 2004
***************
*** 4692,4695 ****
--- 4692,4715 ----
  }
  
+ #if defined (HANDLE_MULTIBYTE)
+ size_t
+ mbstrlen (s)
+      const char *s;
+ {
+   size_t clen, nc;
+   mbstate_t mbs;
+ 
+   nc = 0;
+   memset (&mbs, 0, sizeof (mbs));
+   while ((clen = mbrlen(s, MB_CUR_MAX, &mbs)) != 0 && (MB_INVALIDCH(clen) == 0))
+     {
+       s += clen;
+       nc++;
+     }
+   return nc;
+ }
+ #endif
+       
+ 
  /* Handle the parameter brace expansion that requires us to return the
     length of a parameter. */
***************
*** 4747,4758 ****
  	{
  	  t = get_dollar_var_value (arg_index);
! 	  number = STRLEN (t);
  	  FREE (t);
  	}
  #if defined (ARRAY_VARS)
!       else if ((var = find_variable (name + 1)) && array_p (var))
  	{
  	  t = array_reference (array_cell (var), 0);
! 	  number = STRLEN (t);
  	}
  #endif
--- 4767,4778 ----
  	{
  	  t = get_dollar_var_value (arg_index);
! 	  number = MB_STRLEN (t);
  	  FREE (t);
  	}
  #if defined (ARRAY_VARS)
!       else if ((var = find_variable (name + 1)) && (invisible_p (var) == 0) && array_p (var))
  	{
  	  t = array_reference (array_cell (var), 0);
! 	  number = MB_STRLEN (t);
  	}
  #endif
***************
*** 4767,4771 ****
  	    dispose_words (list);
  
! 	  number = STRLEN (t);
  	  FREE (t);
  	}
--- 4787,4791 ----
  	    dispose_words (list);
  
! 	  number = MB_STRLEN (t);
  	  FREE (t);
  	}
***************
*** 4872,4876 ****
      case VT_VARIABLE:
      case VT_ARRAYMEMBER:
!       len = strlen (value);
        break;
      case VT_POSPARMS:
--- 4892,4896 ----
      case VT_VARIABLE:
      case VT_ARRAYMEMBER:
!       len = MB_STRLEN (value);
        break;
      case VT_POSPARMS:
*** ../bash-3.0/include/shmbutil.h	Mon Apr 19 09:59:42 2004
--- include/shmbutil.h	Thu Sep  2 15:20:47 2004
***************
*** 32,35 ****
--- 32,37 ----
  extern size_t xdupmbstowcs __P((wchar_t **, char ***, const char *));
  
+ extern size_t mbstrlen __P((const char *));
+ 
  extern char *xstrchr __P((const char *, int));
  
***************
*** 39,42 ****
--- 41,47 ----
  #endif
  
+ #define MBSLEN(s)	(((s) && (s)[0]) ? ((s)[1] ? mbstrlen (s) : 1) : 0)
+ #define MB_STRLEN(s)	((MB_CUR_MAX > 1) ? MBSLEN (s) : STRLEN (s))
+ 
  #else /* !HANDLE_MULTIBYTE */
  
***************
*** 54,57 ****
--- 59,64 ----
  #define MB_NULLWCH(x)		(0)
  #endif
+ 
+ #define MB_STRLEN(s)		(STRLEN(s))
  
  #endif /* !HANDLE_MULTIBYTE */

*** ../bash-3.0/patchlevel.h	Wed Aug 22 08:05:39 2001
--- patchlevel.h	Thu Sep  2 15:04:32 2004
***************
*** 26,30 ****
     looks for to find the patch level (for the sccs version string). */
  
! #define PATCHLEVEL 3
  
  #endif /* _PATCHLEVEL_H_ */
--- 26,30 ----
     looks for to find the patch level (for the sccs version string). */
  
! #define PATCHLEVEL 4
  
  #endif /* _PATCHLEVEL_H_ */