cpython: 44c8a9d80595 (original) (raw)
Mercurial > cpython
changeset 84298:44c8a9d80595
Issue #11016: Detect integer conversion on conversion from Python int to C mode_t [#11016]
Victor Stinner victor.stinner@gmail.com | |
---|---|
date | Sun, 23 Jun 2013 22:57:43 +0200 |
parents | 153f7c0df033 |
children | e290451883d0 cb70776241bb |
files | Modules/_stat.c |
diffstat | 1 files changed, 27 insertions(+), 13 deletions(-)[+] [-] Modules/_stat.c 40 |
line wrap: on
line diff
--- a/Modules/_stat.c +++ b/Modules/_stat.c @@ -258,15 +258,32 @@ typedef unsigned short mode_t;
define SF_SNAPSHOT 0x00200000
#endif +static mode_t +_PyLong_AsMode_t(PyObject *op) +{
- value = PyLong_AsUnsignedLong(op);
- if ((value == (unsigned long)-1) && PyErr_Occurred())
return (mode_t)-1;[](#l1.15)
- mode = (mode_t)value;
- if ((unsigned long)mode != value) {
PyErr_SetString(PyExc_OverflowError, "mode out of range");[](#l1.19)
return (mode_t)-1;[](#l1.20)
- }
- return mode;
+} + #define stat_S_ISFUNC(isfunc, doc) [](#l1.26) static PyObject * [](#l1.27) stat_ ##isfunc (PyObject *self, PyObject *omode) [](#l1.28) { [](#l1.29)
unsigned long mode = PyLong_AsUnsignedLong(omode); \[](#l1.30)
if ((mode == (unsigned long)-1) && PyErr_Occurred()) { \[](#l1.31)
mode_t mode = _PyLong_AsMode_t(omode); \[](#l1.32)
if ((mode == (mode_t)-1) && PyErr_Occurred()) \[](#l1.33) return NULL; \[](#l1.34)
} [](#l1.37) PyDoc_STRVAR(stat_ ## isfunc ## _doc, doc) @@ -318,10 +335,9 @@ PyDoc_STRVAR(stat_S_IMODE_doc, static PyObject * stat_S_IMODE(PyObject *self, PyObject *omode) {} \[](#l1.35) return PyBool_FromLong(isfunc(mode)); \[](#l1.36)
- unsigned long mode = PyLong_AsUnsignedLong(omode);
- if ((mode == (unsigned long)-1) && PyErr_Occurred()) {
@@ -332,10 +348,9 @@ PyDoc_STRVAR(stat_S_IFMT_doc, static PyObject * stat_S_IFMT(PyObject *self, PyObject *omode) {
- unsigned long mode = PyLong_AsUnsignedLong(omode);
- if ((mode == (unsigned long)-1) && PyErr_Occurred()) {
@@ -395,12 +410,11 @@ static PyObject * stat_filemode(PyObject *self, PyObject *omode) { char buf[10];