mirror of
https://github.com/python/cpython.git
synced 2025-11-26 21:33:10 +00:00
Issue #11016: Detect integer conversion on conversion from Python int to C mode_t
This commit is contained in:
parent
42471ad7dd
commit
1ce46d99db
1 changed files with 27 additions and 13 deletions
|
|
@ -258,15 +258,32 @@ typedef unsigned short mode_t;
|
||||||
# define SF_SNAPSHOT 0x00200000
|
# define SF_SNAPSHOT 0x00200000
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static mode_t
|
||||||
|
_PyLong_AsMode_t(PyObject *op)
|
||||||
|
{
|
||||||
|
unsigned long value;
|
||||||
|
mode_t mode;
|
||||||
|
|
||||||
|
value = PyLong_AsUnsignedLong(op);
|
||||||
|
if ((value == (unsigned long)-1) && PyErr_Occurred())
|
||||||
|
return (mode_t)-1;
|
||||||
|
|
||||||
|
mode = (mode_t)value;
|
||||||
|
if ((unsigned long)mode != value) {
|
||||||
|
PyErr_SetString(PyExc_OverflowError, "mode out of range");
|
||||||
|
return (mode_t)-1;
|
||||||
|
}
|
||||||
|
return mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#define stat_S_ISFUNC(isfunc, doc) \
|
#define stat_S_ISFUNC(isfunc, doc) \
|
||||||
static PyObject * \
|
static PyObject * \
|
||||||
stat_ ##isfunc (PyObject *self, PyObject *omode) \
|
stat_ ##isfunc (PyObject *self, PyObject *omode) \
|
||||||
{ \
|
{ \
|
||||||
unsigned long mode = PyLong_AsUnsignedLong(omode); \
|
mode_t mode = _PyLong_AsMode_t(omode); \
|
||||||
if ((mode == (unsigned long)-1) && PyErr_Occurred()) { \
|
if ((mode == (mode_t)-1) && PyErr_Occurred()) \
|
||||||
return NULL; \
|
return NULL; \
|
||||||
} \
|
|
||||||
return PyBool_FromLong(isfunc(mode)); \
|
return PyBool_FromLong(isfunc(mode)); \
|
||||||
} \
|
} \
|
||||||
PyDoc_STRVAR(stat_ ## isfunc ## _doc, doc)
|
PyDoc_STRVAR(stat_ ## isfunc ## _doc, doc)
|
||||||
|
|
@ -318,10 +335,9 @@ PyDoc_STRVAR(stat_S_IMODE_doc,
|
||||||
static PyObject *
|
static PyObject *
|
||||||
stat_S_IMODE(PyObject *self, PyObject *omode)
|
stat_S_IMODE(PyObject *self, PyObject *omode)
|
||||||
{
|
{
|
||||||
unsigned long mode = PyLong_AsUnsignedLong(omode);
|
mode_t mode = _PyLong_AsMode_t(omode);
|
||||||
if ((mode == (unsigned long)-1) && PyErr_Occurred()) {
|
if ((mode == (mode_t)-1) && PyErr_Occurred())
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
return PyLong_FromUnsignedLong(mode & S_IMODE);
|
return PyLong_FromUnsignedLong(mode & S_IMODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -332,10 +348,9 @@ PyDoc_STRVAR(stat_S_IFMT_doc,
|
||||||
static PyObject *
|
static PyObject *
|
||||||
stat_S_IFMT(PyObject *self, PyObject *omode)
|
stat_S_IFMT(PyObject *self, PyObject *omode)
|
||||||
{
|
{
|
||||||
unsigned long mode = PyLong_AsUnsignedLong(omode);
|
mode_t mode = _PyLong_AsMode_t(omode);
|
||||||
if ((mode == (unsigned long)-1) && PyErr_Occurred()) {
|
if ((mode == (mode_t)-1) && PyErr_Occurred())
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
return PyLong_FromUnsignedLong(mode & S_IFMT);
|
return PyLong_FromUnsignedLong(mode & S_IFMT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -395,12 +410,11 @@ static PyObject *
|
||||||
stat_filemode(PyObject *self, PyObject *omode)
|
stat_filemode(PyObject *self, PyObject *omode)
|
||||||
{
|
{
|
||||||
char buf[10];
|
char buf[10];
|
||||||
unsigned long mode;
|
mode_t mode;
|
||||||
|
|
||||||
mode = PyLong_AsUnsignedLong(omode);
|
mode = _PyLong_AsMode_t(omode);
|
||||||
if ((mode == (unsigned long)-1) && PyErr_Occurred()) {
|
if ((mode == (mode_t)-1) && PyErr_Occurred())
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
buf[0] = filetype(mode);
|
buf[0] = filetype(mode);
|
||||||
fileperm(mode, &buf[1]);
|
fileperm(mode, &buf[1]);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue