Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
12cf60c7
Kaydet (Commit)
12cf60c7
authored
May 20, 2016
tarafından
Serhiy Storchaka
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #26168: Fixed possible refleaks in failing Py_BuildValue() with the "N"
format unit.
üst
6546d7ca
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
172 additions
and
43 deletions
+172
-43
test_capi.py
Lib/test/test_capi.py
+6
-1
NEWS
Misc/NEWS
+3
-0
_testcapimodule.c
Modules/_testcapimodule.c
+95
-0
modsupport.c
Python/modsupport.c
+68
-42
No files found.
Lib/test/test_capi.py
Dosyayı görüntüle @
12cf60c7
...
@@ -16,6 +16,11 @@ except ImportError:
...
@@ -16,6 +16,11 @@ except ImportError:
# Skip this test if the _testcapi module isn't available.
# Skip this test if the _testcapi module isn't available.
_testcapi
=
support
.
import_module
(
'_testcapi'
)
_testcapi
=
support
.
import_module
(
'_testcapi'
)
class
CAPITest
(
unittest
.
TestCase
):
def
test_buildvalue_N
(
self
):
_testcapi
.
test_buildvalue_N
()
@unittest.skipUnless
(
threading
,
'Threading required for this test.'
)
@unittest.skipUnless
(
threading
,
'Threading required for this test.'
)
class
TestPendingCalls
(
unittest
.
TestCase
):
class
TestPendingCalls
(
unittest
.
TestCase
):
...
@@ -132,7 +137,7 @@ def test_main():
...
@@ -132,7 +137,7 @@ def test_main():
except
_testcapi
.
error
:
except
_testcapi
.
error
:
raise
support
.
TestFailed
,
sys
.
exc_info
()[
1
]
raise
support
.
TestFailed
,
sys
.
exc_info
()[
1
]
support
.
run_unittest
(
TestPendingCalls
,
TestThreadState
)
support
.
run_unittest
(
CAPITest
,
TestPendingCalls
,
TestThreadState
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
test_main
()
test_main
()
Misc/NEWS
Dosyayı görüntüle @
12cf60c7
...
@@ -10,6 +10,9 @@ What's New in Python 2.7.12?
...
@@ -10,6 +10,9 @@ What's New in Python 2.7.12?
Core and Builtins
Core and Builtins
-----------------
-----------------
- Issue #26168: Fixed possible refleaks in failing Py_BuildValue() with the "N"
format unit.
- Issue #27039: Fixed bytearray.remove() for values greater than 127. Patch by
- Issue #27039: Fixed bytearray.remove() for values greater than 127. Patch by
Joe Jevnik.
Joe Jevnik.
...
...
Modules/_testcapimodule.c
Dosyayı görüntüle @
12cf60c7
...
@@ -930,6 +930,100 @@ test_L_code(PyObject *self)
...
@@ -930,6 +930,100 @@ test_L_code(PyObject *self)
#endif
/* ifdef HAVE_LONG_LONG */
#endif
/* ifdef HAVE_LONG_LONG */
static
PyObject
*
return_none
(
void
*
unused
)
{
Py_RETURN_NONE
;
}
static
PyObject
*
raise_error
(
void
*
unused
)
{
PyErr_SetNone
(
PyExc_ValueError
);
return
NULL
;
}
static
int
test_buildvalue_N_error
(
const
char
*
fmt
)
{
PyObject
*
arg
,
*
res
;
arg
=
PyList_New
(
0
);
if
(
arg
==
NULL
)
{
return
-
1
;
}
Py_INCREF
(
arg
);
res
=
Py_BuildValue
(
fmt
,
return_none
,
NULL
,
arg
);
if
(
res
==
NULL
)
{
return
-
1
;
}
Py_DECREF
(
res
);
if
(
Py_REFCNT
(
arg
)
!=
1
)
{
PyErr_Format
(
TestError
,
"test_buildvalue_N: "
"arg was not decrefed in successful "
"Py_BuildValue(
\"
%s
\"
)"
,
fmt
);
return
-
1
;
}
Py_INCREF
(
arg
);
res
=
Py_BuildValue
(
fmt
,
raise_error
,
NULL
,
arg
);
if
(
res
!=
NULL
||
!
PyErr_Occurred
())
{
PyErr_Format
(
TestError
,
"test_buildvalue_N: "
"Py_BuildValue(
\"
%s
\"
) didn't complain"
,
fmt
);
return
-
1
;
}
PyErr_Clear
();
if
(
Py_REFCNT
(
arg
)
!=
1
)
{
PyErr_Format
(
TestError
,
"test_buildvalue_N: "
"arg was not decrefed in failed "
"Py_BuildValue(
\"
%s
\"
)"
,
fmt
);
return
-
1
;
}
Py_DECREF
(
arg
);
return
0
;
}
static
PyObject
*
test_buildvalue_N
(
PyObject
*
self
,
PyObject
*
noargs
)
{
PyObject
*
arg
,
*
res
;
arg
=
PyList_New
(
0
);
if
(
arg
==
NULL
)
{
return
NULL
;
}
Py_INCREF
(
arg
);
res
=
Py_BuildValue
(
"N"
,
arg
);
if
(
res
==
NULL
)
{
return
NULL
;
}
if
(
res
!=
arg
)
{
return
raiseTestError
(
"test_buildvalue_N"
,
"Py_BuildValue(
\"
N
\"
) returned wrong result"
);
}
if
(
Py_REFCNT
(
arg
)
!=
2
)
{
return
raiseTestError
(
"test_buildvalue_N"
,
"arg was not decrefed in Py_BuildValue(
\"
N
\"
)"
);
}
Py_DECREF
(
res
);
Py_DECREF
(
arg
);
if
(
test_buildvalue_N_error
(
"O&N"
)
<
0
)
return
NULL
;
if
(
test_buildvalue_N_error
(
"(O&N)"
)
<
0
)
return
NULL
;
if
(
test_buildvalue_N_error
(
"[O&N]"
)
<
0
)
return
NULL
;
if
(
test_buildvalue_N_error
(
"{O&N}"
)
<
0
)
return
NULL
;
if
(
test_buildvalue_N_error
(
"{()O&(())N}"
)
<
0
)
return
NULL
;
Py_RETURN_NONE
;
}
static
PyObject
*
static
PyObject
*
get_args
(
PyObject
*
self
,
PyObject
*
args
)
get_args
(
PyObject
*
self
,
PyObject
*
args
)
{
{
...
@@ -2414,6 +2508,7 @@ static PyMethodDef TestMethods[] = {
...
@@ -2414,6 +2508,7 @@ static PyMethodDef TestMethods[] = {
{
"test_with_docstring"
,
(
PyCFunction
)
test_with_docstring
,
METH_NOARGS
,
{
"test_with_docstring"
,
(
PyCFunction
)
test_with_docstring
,
METH_NOARGS
,
PyDoc_STR
(
"This is a pretty normal docstring."
)},
PyDoc_STR
(
"This is a pretty normal docstring."
)},
{
"test_buildvalue_N"
,
test_buildvalue_N
,
METH_NOARGS
},
{
"get_args"
,
get_args
,
METH_VARARGS
},
{
"get_args"
,
get_args
,
METH_VARARGS
},
{
"get_kwargs"
,
(
PyCFunction
)
get_kwargs
,
METH_VARARGS
|
METH_KEYWORDS
},
{
"get_kwargs"
,
(
PyCFunction
)
get_kwargs
,
METH_VARARGS
|
METH_KEYWORDS
},
{
"getargs_tuple"
,
getargs_tuple
,
METH_VARARGS
},
{
"getargs_tuple"
,
getargs_tuple
,
METH_VARARGS
},
...
...
Python/modsupport.c
Dosyayı görüntüle @
12cf60c7
...
@@ -156,48 +156,83 @@ static PyObject *do_mkdict(const char**, va_list *, int, int, int);
...
@@ -156,48 +156,83 @@ static PyObject *do_mkdict(const char**, va_list *, int, int, int);
static
PyObject
*
do_mkvalue
(
const
char
**
,
va_list
*
,
int
);
static
PyObject
*
do_mkvalue
(
const
char
**
,
va_list
*
,
int
);
static
void
do_ignore
(
const
char
**
p_format
,
va_list
*
p_va
,
int
endchar
,
int
n
,
int
flags
)
{
PyObject
*
v
;
int
i
;
assert
(
PyErr_Occurred
());
v
=
PyTuple_New
(
n
);
for
(
i
=
0
;
i
<
n
;
i
++
)
{
PyObject
*
exception
,
*
value
,
*
tb
,
*
w
;
PyErr_Fetch
(
&
exception
,
&
value
,
&
tb
);
w
=
do_mkvalue
(
p_format
,
p_va
,
flags
);
PyErr_Restore
(
exception
,
value
,
tb
);
if
(
w
!=
NULL
)
{
if
(
v
!=
NULL
)
{
PyTuple_SET_ITEM
(
v
,
i
,
w
);
}
else
{
Py_DECREF
(
w
);
}
}
}
Py_XDECREF
(
v
);
if
(
**
p_format
!=
endchar
)
{
PyErr_SetString
(
PyExc_SystemError
,
"Unmatched paren in format"
);
return
;
}
if
(
endchar
)
++*
p_format
;
}
static
PyObject
*
static
PyObject
*
do_mkdict
(
const
char
**
p_format
,
va_list
*
p_va
,
int
endchar
,
int
n
,
int
flags
)
do_mkdict
(
const
char
**
p_format
,
va_list
*
p_va
,
int
endchar
,
int
n
,
int
flags
)
{
{
PyObject
*
d
;
PyObject
*
d
;
int
i
;
int
i
;
int
itemfailed
=
0
;
if
(
n
<
0
)
if
(
n
<
0
)
return
NULL
;
return
NULL
;
if
((
d
=
PyDict_New
())
==
NULL
)
if
(
n
%
2
)
{
PyErr_SetString
(
PyExc_SystemError
,
"Bad dict format"
);
do_ignore
(
p_format
,
p_va
,
endchar
,
n
,
flags
);
return
NULL
;
return
NULL
;
}
/* Note that we can't bail immediately on error as this will leak
/* Note that we can't bail immediately on error as this will leak
refcounts on any 'N' arguments. */
refcounts on any 'N' arguments. */
if
((
d
=
PyDict_New
())
==
NULL
)
{
do_ignore
(
p_format
,
p_va
,
endchar
,
n
,
flags
);
return
NULL
;
}
for
(
i
=
0
;
i
<
n
;
i
+=
2
)
{
for
(
i
=
0
;
i
<
n
;
i
+=
2
)
{
PyObject
*
k
,
*
v
;
PyObject
*
k
,
*
v
;
int
err
;
k
=
do_mkvalue
(
p_format
,
p_va
,
flags
);
k
=
do_mkvalue
(
p_format
,
p_va
,
flags
);
if
(
k
==
NULL
)
{
if
(
k
==
NULL
)
{
itemfailed
=
1
;
do_ignore
(
p_format
,
p_va
,
endchar
,
n
-
i
-
1
,
flags
)
;
Py_
INCREF
(
Py_None
);
Py_
DECREF
(
d
);
k
=
Py_None
;
return
NULL
;
}
}
v
=
do_mkvalue
(
p_format
,
p_va
,
flags
);
v
=
do_mkvalue
(
p_format
,
p_va
,
flags
);
if
(
v
==
NULL
)
{
if
(
v
==
NULL
||
PyDict_SetItem
(
d
,
k
,
v
)
<
0
)
{
itemfailed
=
1
;
do_ignore
(
p_format
,
p_va
,
endchar
,
n
-
i
-
2
,
flags
);
Py_INCREF
(
Py_None
);
Py_DECREF
(
k
);
v
=
Py_None
;
Py_XDECREF
(
v
);
}
err
=
PyDict_SetItem
(
d
,
k
,
v
);
Py_DECREF
(
k
);
Py_DECREF
(
v
);
if
(
err
<
0
||
itemfailed
)
{
Py_DECREF
(
d
);
Py_DECREF
(
d
);
return
NULL
;
return
NULL
;
}
}
Py_DECREF
(
k
);
Py_DECREF
(
v
);
}
}
if
(
d
!=
NULL
&&
**
p_format
!=
endchar
)
{
if
(
**
p_format
!=
endchar
)
{
Py_DECREF
(
d
);
Py_DECREF
(
d
);
d
=
NULL
;
PyErr_SetString
(
PyExc_SystemError
,
PyErr_SetString
(
PyExc_SystemError
,
"Unmatched paren in format"
);
"Unmatched paren in format"
);
return
NULL
;
}
}
else
if
(
endchar
)
if
(
endchar
)
++*
p_format
;
++*
p_format
;
return
d
;
return
d
;
}
}
...
@@ -207,29 +242,24 @@ do_mklist(const char **p_format, va_list *p_va, int endchar, int n, int flags)
...
@@ -207,29 +242,24 @@ do_mklist(const char **p_format, va_list *p_va, int endchar, int n, int flags)
{
{
PyObject
*
v
;
PyObject
*
v
;
int
i
;
int
i
;
int
itemfailed
=
0
;
if
(
n
<
0
)
if
(
n
<
0
)
return
NULL
;
return
NULL
;
v
=
PyList_New
(
n
);
if
(
v
==
NULL
)
return
NULL
;
/* Note that we can't bail immediately on error as this will leak
/* Note that we can't bail immediately on error as this will leak
refcounts on any 'N' arguments. */
refcounts on any 'N' arguments. */
v
=
PyList_New
(
n
);
if
(
v
==
NULL
)
{
do_ignore
(
p_format
,
p_va
,
endchar
,
n
,
flags
);
return
NULL
;
}
for
(
i
=
0
;
i
<
n
;
i
++
)
{
for
(
i
=
0
;
i
<
n
;
i
++
)
{
PyObject
*
w
=
do_mkvalue
(
p_format
,
p_va
,
flags
);
PyObject
*
w
=
do_mkvalue
(
p_format
,
p_va
,
flags
);
if
(
w
==
NULL
)
{
if
(
w
==
NULL
)
{
itemfailed
=
1
;
do_ignore
(
p_format
,
p_va
,
endchar
,
n
-
i
-
1
,
flags
)
;
Py_
INCREF
(
Py_None
);
Py_
DECREF
(
v
);
w
=
Py_None
;
return
NULL
;
}
}
PyList_SET_ITEM
(
v
,
i
,
w
);
PyList_SET_ITEM
(
v
,
i
,
w
);
}
}
if
(
itemfailed
)
{
/* do_mkvalue() should have already set an error */
Py_DECREF
(
v
);
return
NULL
;
}
if
(
**
p_format
!=
endchar
)
{
if
(
**
p_format
!=
endchar
)
{
Py_DECREF
(
v
);
Py_DECREF
(
v
);
PyErr_SetString
(
PyExc_SystemError
,
PyErr_SetString
(
PyExc_SystemError
,
...
@@ -257,27 +287,23 @@ do_mktuple(const char **p_format, va_list *p_va, int endchar, int n, int flags)
...
@@ -257,27 +287,23 @@ do_mktuple(const char **p_format, va_list *p_va, int endchar, int n, int flags)
{
{
PyObject
*
v
;
PyObject
*
v
;
int
i
;
int
i
;
int
itemfailed
=
0
;
if
(
n
<
0
)
if
(
n
<
0
)
return
NULL
;
return
NULL
;
if
((
v
=
PyTuple_New
(
n
))
==
NULL
)
return
NULL
;
/* Note that we can't bail immediately on error as this will leak
/* Note that we can't bail immediately on error as this will leak
refcounts on any 'N' arguments. */
refcounts on any 'N' arguments. */
if
((
v
=
PyTuple_New
(
n
))
==
NULL
)
{
do_ignore
(
p_format
,
p_va
,
endchar
,
n
,
flags
);
return
NULL
;
}
for
(
i
=
0
;
i
<
n
;
i
++
)
{
for
(
i
=
0
;
i
<
n
;
i
++
)
{
PyObject
*
w
=
do_mkvalue
(
p_format
,
p_va
,
flags
);
PyObject
*
w
=
do_mkvalue
(
p_format
,
p_va
,
flags
);
if
(
w
==
NULL
)
{
if
(
w
==
NULL
)
{
itemfailed
=
1
;
do_ignore
(
p_format
,
p_va
,
endchar
,
n
-
i
-
1
,
flags
)
;
Py_
INCREF
(
Py_None
);
Py_
DECREF
(
v
);
w
=
Py_None
;
return
NULL
;
}
}
PyTuple_SET_ITEM
(
v
,
i
,
w
);
PyTuple_SET_ITEM
(
v
,
i
,
w
);
}
}
if
(
itemfailed
)
{
/* do_mkvalue() should have already set an error */
Py_DECREF
(
v
);
return
NULL
;
}
if
(
**
p_format
!=
endchar
)
{
if
(
**
p_format
!=
endchar
)
{
Py_DECREF
(
v
);
Py_DECREF
(
v
);
PyErr_SetString
(
PyExc_SystemError
,
PyErr_SetString
(
PyExc_SystemError
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment