diff options
Diffstat (limited to 'Objects/stringobject.c')
-rw-r--r-- | Objects/stringobject.c | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/Objects/stringobject.c b/Objects/stringobject.c index 3c03b9ee2a..99a16ed174 100644 --- a/Objects/stringobject.c +++ b/Objects/stringobject.c @@ -3553,10 +3553,26 @@ PyString_InternInPlace(PyObject **p) Py_DECREF(s); return; } - t = (PyObject *)s; - if (PyDict_SetItem(interned, t, t) == 0) { - s->ob_sinterned = t; - return; + /* Ensure that only true string objects appear in the intern dict, + and as the value of ob_sinterned. */ + if (PyString_CheckExact(s)) { + t = (PyObject *)s; + if (PyDict_SetItem(interned, t, t) == 0) { + s->ob_sinterned = t; + return; + } + } + else { + t = PyString_FromStringAndSize(PyString_AS_STRING(s), + PyString_GET_SIZE(s)); + if (t != NULL) { + if (PyDict_SetItem(interned, t, t) == 0) { + *p = s->ob_sinterned = t; + Py_DECREF(s); + return; + } + Py_DECREF(t); + } } PyErr_Clear(); } |