Re: [patch] mpi/mpi-mpow: NULL dereference on allocation failure

From: Kasatkin, Dmitry
Date: Mon Nov 21 2011 - 10:19:13 EST


On Mon, Nov 21, 2011 at 4:50 PM, Dan Carpenter <dan.carpenter@xxxxxxxxxx> wrote:
> We can't call mpi_free() on the elements if the first kzalloc() fails.
>
> Signed-off-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx>

Signed-off-by: Dmitry Kasatkin <dmitry.kasatkin@xxxxxxxxx>

>
> diff --git a/lib/mpi/mpi-mpow.c b/lib/mpi/mpi-mpow.c
> index 4cc7593..7328d0d 100644
> --- a/lib/mpi/mpi-mpow.c
> +++ b/lib/mpi/mpi-mpow.c
> @@ -73,7 +73,7 @@ int mpi_mulpowm(MPI res, MPI *basearray, MPI *exparray, MPI m)
>
> Â Â Â ÂG = kzalloc((1 << k) * sizeof *G, GFP_KERNEL);
> Â Â Â Âif (!G)
> - Â Â Â Â Â Â Â goto nomem;
> + Â Â Â Â Â Â Â goto err_out;
>
> Â Â Â Â/* and calculate */
> Â Â Â Âtmp = mpi_alloc(mpi_get_nlimbs(m) + 1);
> @@ -129,5 +129,6 @@ nomem:
> Â Â Â Âfor (i = 0; i < (1 << k); i++)
> Â Â Â Â Â Â Â Âmpi_free(G[i]);
> Â Â Â Âkfree(G);
> +err_out:
> Â Â Â Âreturn rc;
> Â}
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/