mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
weakref_repr(), proxy_repr(): Conversion of sprintf() to
PyOS_snprintf() for buffer overrun avoidance.
This commit is contained in:
parent
e5c492d72a
commit
d586756dc5
1 changed files with 11 additions and 8 deletions
|
@ -131,13 +131,15 @@ weakref_repr(PyWeakReference *self)
|
|||
{
|
||||
char buffer[256];
|
||||
if (PyWeakref_GET_OBJECT(self) == Py_None) {
|
||||
sprintf(buffer, "<weakref at %lx; dead>",
|
||||
(long)(self));
|
||||
PyOS_snprintf(buffer, sizeof(buffer), "<weakref at %lx; dead>",
|
||||
(long)(self));
|
||||
}
|
||||
else {
|
||||
sprintf(buffer, "<weakref at %#lx; to '%.50s' at %#lx>",
|
||||
(long)(self), PyWeakref_GET_OBJECT(self)->ob_type->tp_name,
|
||||
(long)(PyWeakref_GET_OBJECT(self)));
|
||||
PyOS_snprintf(buffer, sizeof(buffer),
|
||||
"<weakref at %#lx; to '%.50s' at %#lx>",
|
||||
(long)(self),
|
||||
PyWeakref_GET_OBJECT(self)->ob_type->tp_name,
|
||||
(long)(PyWeakref_GET_OBJECT(self)));
|
||||
}
|
||||
return PyString_FromString(buffer);
|
||||
}
|
||||
|
@ -265,9 +267,10 @@ static PyObject *
|
|||
proxy_repr(PyWeakReference *proxy)
|
||||
{
|
||||
char buf[160];
|
||||
sprintf(buf, "<weakref at %p to %.100s at %p>", proxy,
|
||||
PyWeakref_GET_OBJECT(proxy)->ob_type->tp_name,
|
||||
PyWeakref_GET_OBJECT(proxy));
|
||||
PyOS_snprintf(buf, sizeof(buf),
|
||||
"<weakref at %p to %.100s at %p>", proxy,
|
||||
PyWeakref_GET_OBJECT(proxy)->ob_type->tp_name,
|
||||
PyWeakref_GET_OBJECT(proxy));
|
||||
return PyString_FromString(buf);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue