[PATCH] lazymanifest: check more return values in filtercopy

Martin von Zweigbergk martinvonz at google.com
Tue Jan 5 23:58:26 CST 2016


On Tue, Jan 5, 2016 at 8:01 AM Augie Fackler <raf at durin42.com> wrote:

> # HG changeset patch
> # User Augie Fackler <raf at durin42.com>
> # Date 1451586702 18000
> #      Thu Dec 31 13:31:42 2015 -0500
> # Node ID 700ae5816d662e0e5dde55c68944329b6eb1b7c0
> # Parent  0bc71f45d3623b231cc3975b48feccce79d1231e
> lazymanifest: check more return values in filtercopy
>
> Spotted by Bryan O'Sullivan (and vexingly not the static analyzer I've
> been using.)
>
> diff --git a/mercurial/manifest.c b/mercurial/manifest.c
> --- a/mercurial/manifest.c
> +++ b/mercurial/manifest.c
> @@ -707,11 +707,20 @@ static lazymanifest *lazymanifest_filter
>         copy->pydata = self->pydata;
>         Py_INCREF(self->pydata);
>         for (i = 0; i < self->numlines; i++) {
> -               PyObject *arg = PyString_FromString(self->lines[i].start);
> -               PyObject *arglist = PyTuple_Pack(1, arg);
> -               PyObject *result = PyObject_CallObject(matchfn, arglist);
> +               PyObject *arg = NULL, *arglist = NULL, *result = NULL;
> +               arg = PyString_FromString(self->lines[i].start);
> +               if (!arg) {
> +                       PyErr_SetString(PyExc_TypeError,
> +                                       "couldn't pack filename");
>

TypeError seems wrong here. Most likely out of memory? Should we just leave
it as whatever it was already set to? We don't set it when PyTuple_Pack()
below fails.


> +                       return NULL;
> +               }
> +               arglist = PyTuple_Pack(1, arg);
> +               Py_DECREF(arg);
> +               if (!arglist) {
> +                       return NULL;
> +               }
> +               result = PyObject_CallObject(matchfn, arglist);
>                 Py_DECREF(arglist);
> -               Py_DECREF(arg);
>                 /* if the callback raised an exception, just let it
>                  * through and give up */
>                 if (!result) {
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> https://selenic.com/mailman/listinfo/mercurial-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20160106/823db641/attachment.html>


More information about the Mercurial-devel mailing list