Kaydet (Commit) d95efe42 authored tarafından Jeremy Hylton's avatar Jeremy Hylton

Check for overflow errors in setrlimit(),

and reflow a long line.
üst ed9e453e
...@@ -142,7 +142,8 @@ resource_setrlimit(PyObject *self, PyObject *args) ...@@ -142,7 +142,8 @@ resource_setrlimit(PyObject *self, PyObject *args)
int resource; int resource;
PyObject *curobj, *maxobj; PyObject *curobj, *maxobj;
if (!PyArg_ParseTuple(args, "i(OO):setrlimit", &resource, &curobj, &maxobj)) if (!PyArg_ParseTuple(args, "i(OO):setrlimit",
&resource, &curobj, &maxobj))
return NULL; return NULL;
if (resource < 0 || resource >= RLIM_NLIMITS) { if (resource < 0 || resource >= RLIM_NLIMITS) {
...@@ -153,13 +154,21 @@ resource_setrlimit(PyObject *self, PyObject *args) ...@@ -153,13 +154,21 @@ resource_setrlimit(PyObject *self, PyObject *args)
#if !defined(HAVE_LARGEFILE_SUPPORT) #if !defined(HAVE_LARGEFILE_SUPPORT)
rl.rlim_cur = PyInt_AsLong(curobj); rl.rlim_cur = PyInt_AsLong(curobj);
if (rl.rlim_cur == -1 && PyErr_Occurred())
return NULL;
rl.rlim_max = PyInt_AsLong(maxobj); rl.rlim_max = PyInt_AsLong(maxobj);
if (rl.rlim_max == -1 && PyErr_Occurred())
return NULL;
#else #else
/* The limits are probably bigger than a long */ /* The limits are probably bigger than a long */
rl.rlim_cur = PyLong_Check(curobj) ? rl.rlim_cur = PyLong_Check(curobj) ?
PyLong_AsLongLong(curobj) : PyInt_AsLong(curobj); PyLong_AsLongLong(curobj) : PyInt_AsLong(curobj);
if (rl.rlim_cur == -1 && PyErr_Occurred())
return NULL;
rl.rlim_max = PyLong_Check(maxobj) ? rl.rlim_max = PyLong_Check(maxobj) ?
PyLong_AsLongLong(maxobj) : PyInt_AsLong(maxobj); PyLong_AsLongLong(maxobj) : PyInt_AsLong(maxobj);
if (rl.rlim_max == -1 && PyErr_Occurred())
return NULL;
#endif #endif
rl.rlim_cur = rl.rlim_cur & RLIM_INFINITY; rl.rlim_cur = rl.rlim_cur & RLIM_INFINITY;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment