mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
Issue #1950: Fixed misusage of PyUnicode_AsString().
This commit is contained in:
parent
999679a23e
commit
a85998af7c
6 changed files with 49 additions and 34 deletions
|
@ -2131,13 +2131,15 @@ get_parent(PyObject *globals, char *buf, Py_ssize_t *p_buflen, int level)
|
|||
|
||||
if ((pkgname != NULL) && (pkgname != Py_None)) {
|
||||
/* __package__ is set, so use it */
|
||||
char *pkgname_str;
|
||||
Py_ssize_t len;
|
||||
|
||||
if (!PyUnicode_Check(pkgname)) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"__package__ set to non-string");
|
||||
return NULL;
|
||||
}
|
||||
len = PyUnicode_GET_SIZE(pkgname);
|
||||
pkgname_str = PyUnicode_AsStringAndSize(pkgname, &len);
|
||||
if (len == 0) {
|
||||
if (level > 0) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
|
@ -2151,7 +2153,7 @@ get_parent(PyObject *globals, char *buf, Py_ssize_t *p_buflen, int level)
|
|||
"Package name too long");
|
||||
return NULL;
|
||||
}
|
||||
strcpy(buf, PyUnicode_AsString(pkgname));
|
||||
strcpy(buf, pkgname_str);
|
||||
} else {
|
||||
/* __package__ not set, so figure it out and set it */
|
||||
modname = PyDict_GetItem(globals, namestr);
|
||||
|
@ -2161,14 +2163,17 @@ get_parent(PyObject *globals, char *buf, Py_ssize_t *p_buflen, int level)
|
|||
modpath = PyDict_GetItem(globals, pathstr);
|
||||
if (modpath != NULL) {
|
||||
/* __path__ is set, so modname is already the package name */
|
||||
Py_ssize_t len = PyUnicode_GET_SIZE(modname);
|
||||
char *modname_str;
|
||||
Py_ssize_t len;
|
||||
int error;
|
||||
|
||||
modname_str = PyUnicode_AsStringAndSize(modname, &len);
|
||||
if (len > MAXPATHLEN) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"Module name too long");
|
||||
return NULL;
|
||||
}
|
||||
strcpy(buf, PyUnicode_AsString(modname));
|
||||
strcpy(buf, modname_str);
|
||||
error = PyDict_SetItem(globals, pkgstr, modname);
|
||||
if (error) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
|
|
|
@ -239,15 +239,22 @@ PyMember_SetOne(char *addr, PyMemberDef *l, PyObject *v)
|
|||
*(PyObject **)addr = v;
|
||||
Py_XDECREF(oldv);
|
||||
break;
|
||||
case T_CHAR:
|
||||
if (PyUnicode_Check(v) && PyUnicode_GetSize(v) == 1) {
|
||||
*(char*)addr = PyUnicode_AsString(v)[0];
|
||||
}
|
||||
else {
|
||||
case T_CHAR: {
|
||||
char *string;
|
||||
Py_ssize_t len;
|
||||
|
||||
if (!PyUnicode_Check(v)) {
|
||||
PyErr_BadArgument();
|
||||
return -1;
|
||||
}
|
||||
string = PyUnicode_AsStringAndSize(v, &len);
|
||||
if (len != 1) {
|
||||
PyErr_BadArgument();
|
||||
return -1;
|
||||
}
|
||||
*(char*)addr = string[0];
|
||||
break;
|
||||
}
|
||||
#ifdef HAVE_LONG_LONG
|
||||
case T_LONGLONG:{
|
||||
PY_LONG_LONG value;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue