~torsknod/+junk/bash-package

« back to all changes in this revision

Viewing changes to debian/patches/bash42-030.diff

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2012-07-12 23:52:40 UTC
  • mfrom: (2.1.14 sid)
  • Revision ID: package-import@ubuntu.com-20120712235240-sj3e8m92irohuvzk
Tags: 4.2-4ubuntu1
Merge with Debian.

Show diffs side-by-side

added added

removed removed

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