File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,11 @@ What's New in Python 2.2.4?
2
2
Release date: XX-XXX-XXXX
3
3
===========================
4
4
5
+ - Fixed a bug in the cache of length-one Unicode strings that could
6
+ lead to a seg fault. The specific problem occurred when an earlier,
7
+ non-fatal error left an uninitialized Unicode object in the
8
+ freelist.
9
+
5
10
- The email package handles some RFC 2231 parameters with missing
6
11
CHARSET fields better. It also includes a patch to parameter
7
12
parsing when semicolons appear inside quotes.
Original file line number Diff line number Diff line change @@ -132,7 +132,12 @@ int unicode_resize(register PyUnicodeObject *unicode,
132
132
instead ! */
133
133
if (unicode == unicode_empty ||
134
134
(unicode -> length == 1 &&
135
- unicode -> str [0 ] < 256 &&
135
+ /* MvL said unicode->str[] may be signed. Python generally assumes
136
+ * an int contains at least 32 bits, and we don't use more than
137
+ * 32 bits even in a UCS4 build, so casting to unsigned int should
138
+ * be correct.
139
+ */
140
+ (unsigned int )unicode -> str [0 ] < 256U &&
136
141
unicode_latin1 [unicode -> str [0 ]] == unicode )) {
137
142
PyErr_SetString (PyExc_SystemError ,
138
143
"can't resize shared unicode objects" );
@@ -211,6 +216,14 @@ PyUnicodeObject *_PyUnicode_New(int length)
211
216
PyErr_NoMemory ();
212
217
goto onError ;
213
218
}
219
+ /* Initialize the first element to guard against cases where
220
+ * the caller fails before initializing str -- unicode_resize()
221
+ * reads str[0], and the Keep-Alive optimization can keep memory
222
+ * allocated for str alive across a call to unicode_dealloc(unicode).
223
+ * We don't want unicode_resize to read uninitialized memory in
224
+ * that case.
225
+ */
226
+ unicode -> str [0 ] = 0 ;
214
227
unicode -> str [length ] = 0 ;
215
228
unicode -> length = length ;
216
229
unicode -> hash = -1 ;
You can’t perform that action at this time.
0 commit comments