[Python-checkins] r70980 - in python/trunk: Lib/test/test_mmap.py Modules/mmapmodule.c

Jack diederich jackdied at gmail.com
Wed Apr 1 22:30:13 CEST 2009


We've gotten this wrong twice so I'm going to let this settle for a
few hours before merging accross all the other branches.
On Wed, Apr 1, 2009 at 4:26 PM, jack.diederich
<python-checkins at python.org> wrote:
> Author: jack.diederich
> Date: Wed Apr  1 22:26:13 2009
> New Revision: 70980
>> Log:
> bounds check arguments to mmap.move().  All of them.  Really.
> fixes crasher on OS X 10.5
>>> Modified:
>   python/trunk/Lib/test/test_mmap.py
>   python/trunk/Modules/mmapmodule.c
>> Modified: python/trunk/Lib/test/test_mmap.py
> ==============================================================================
> --- python/trunk/Lib/test/test_mmap.py  (original)
> +++ python/trunk/Lib/test/test_mmap.py  Wed Apr  1 22:26:13 2009
> @@ -359,15 +359,22 @@
>                 m.move(source, dest, size)
>             except ValueError:
>                 pass
> -        self.assertRaises(ValueError, m.move, -1, -1, -1)
> -        self.assertRaises(ValueError, m.move, -1, -1, 0)
> -        self.assertRaises(ValueError, m.move, -1, 0, -1)
> -        self.assertRaises(ValueError, m.move, 0, -1, -1)
> -        self.assertRaises(ValueError, m.move, -1, 0, 0)
> -        self.assertRaises(ValueError, m.move, 0, -1, 0)
> -        self.assertRaises(ValueError, m.move, 0, 0, -1)
> +
> +        offsets = [(-1, -1, -1), (-1, -1, 0), (-1, 0, -1), (0, -1, -1),
> +                   (-1, 0, 0), (0, -1, 0), (0, 0, -1)]
> +        for source, dest, size in offsets:
> +            self.assertRaises(ValueError, m.move, source, dest, size)
> +
>         m.close()
>> +        m = mmap.mmap(-1, 1) # single byte
> +        self.assertRaises(ValueError, m.move, 0, 0, 2)
> +        self.assertRaises(ValueError, m.move, 1, 0, 1)
> +        self.assertRaises(ValueError, m.move, 0, 1, 1)
> +        m.move(0, 0, 1)
> +        m.move(0, 0, 0)
> +
> +
>     def test_anonymous(self):
>         # anonymous mmap.mmap(-1, PAGE)
>         m = mmap.mmap(-1, PAGESIZE)
>> Modified: python/trunk/Modules/mmapmodule.c
> ==============================================================================
> --- python/trunk/Modules/mmapmodule.c   (original)
> +++ python/trunk/Modules/mmapmodule.c   Wed Apr  1 22:26:13 2009
> @@ -609,23 +609,23 @@
>  static PyObject *
>  mmap_move_method(mmap_object *self, PyObject *args)
>  {
> -       unsigned long dest, src, count;
> +       unsigned long dest, src, cnt;
>        CHECK_VALID(NULL);
> -       if (!PyArg_ParseTuple(args, "kkk:move", &dest, &src, &count) ||
> +       if (!PyArg_ParseTuple(args, "kkk:move", &dest, &src, &cnt) ||
>            !is_writeable(self)) {
>                return NULL;
>        } else {
>                /* bounds check the values */
> -               unsigned long pos = src > dest ? src : dest;
> -               if (self->size < pos || count > self->size - pos) {
> +               if (cnt < 0 || (cnt + dest) < cnt || (cnt + src) < cnt ||
> +                  src < 0 || src > self->size || (src + cnt) > self->size ||
> +                  dest < 0 || dest > self->size || (dest + cnt) > self->size) {
>                        PyErr_SetString(PyExc_ValueError,
> -                                       "source or destination out of range");
> +                               "source, destination, or count out of range");
>                        return NULL;
> -               } else {
> -                       memmove(self->data+dest, self->data+src, count);
> -                       Py_INCREF(Py_None);
> -                       return Py_None;
>                }
> +               memmove(self->data+dest, self->data+src, cnt);
> +               Py_INCREF(Py_None);
> +               return Py_None;
>        }
>  }
>> _______________________________________________
> Python-checkins mailing list
> Python-checkins at python.org
> http://mail.python.org/mailman/listinfo/python-checkins
>


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /