comparison Python/structmember.c @ 78992:afe55cd04119 3.2

Fix null pointer dereferencing in structmember.c PyMember_SetOne() for T_CHAR. _PyUnicode_AsStringAndSize() can return NULL without touching the len argument. Also remove unnecessary PyUnicode_Check(), _PyUnicode_AsStringAndSize() performance the test again. CID 486815
author Christian Heimes <christian@cheimes.de>
date Tue, 11 Sep 2012 17:30:53 +0200
parents 3c9232a684ae
children
comparison
equal deleted inserted replaced
78986:8a40bc71c072 78992:afe55cd04119
252 break; 252 break;
253 case T_CHAR: { 253 case T_CHAR: {
254 char *string; 254 char *string;
255 Py_ssize_t len; 255 Py_ssize_t len;
256 256
257 if (!PyUnicode_Check(v)) {
258 PyErr_BadArgument();
259 return -1;
260 }
261 string = _PyUnicode_AsStringAndSize(v, &len); 257 string = _PyUnicode_AsStringAndSize(v, &len);
262 if (len != 1) { 258 if (string == NULL || len != 1) {
263 PyErr_BadArgument(); 259 PyErr_BadArgument();
264 return -1; 260 return -1;
265 } 261 }
266 *(char*)addr = string[0]; 262 *(char*)addr = string[0];
267 break; 263 break;